To programmaictlly the content of the app, we need to contect storyboard to a view controller.
To does that, we need to create new file call it ' Productviewcontroller ', subclass should Uiviewcontroller:
Delete Some uncessary code, the remain code should looks like:
Import UIKit class Productviewcontroller:uiviewcontroller { override func viewdidload () { Super.viewdidload () }}
Link View to Controller:
Click The View panel, and on the right side give the Custom class name as 'productviewcontroller':
Link UI elements to outlets:
Click ' Ctrl ' & drag the image point to the code:
Give the name and save.
We can use ' image Literal ' to auto Select the image:
The same for the label and then the code looks like:
Import UIKit class Productviewcontroller:uiviewcontroller { var productnamelabel:uilabel! var productviewimage:uiimageview! Override func viewdidload () { super.viewdidload () "1937 Desk Phone" ; " Phone-fullscreen3 " ); }}
class Courseviewcontroller: Uiviewcontroller {@IBOutlet weak var Coursenamelabel:uilabel! @IBOutlet weak var courseimageview:uiimageview! override Func Viewdidload () {super.viewdidload () var coursename = app Evolution with Swift Coursenamelabel.text = Coursename courseimageview.image = UIImage (named: "Course-badge" }}
@IBAction Func addproductaction (_ Sender:uibutton) { print ("button tapped" ) }
[Swift] Storyboard Outlet and action