[Swift] Storyboard Outlet and action

Source: Internet
Author: User
Tags uikit

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.