Use Main.storyboard to pull in controls and implement events in Xcode (Swift language)

Source: Internet
Author: User

How do I pull a control inside a main.storyboard in Xcode and implement a simple effect? I just contact Swift language soon, for the operation of the IDE is very unfamiliar, do not understand the online reference on the online predecessors of the article. I'll show you how to use the Swift language with Main.storyboard to demonstrate a small example of a new Singleview application here.

The created application has automatically created a well-connected viewcontroller with Main.storyboard.

Next we add a Uitextfield and UIButton to the view within the Main.storyboard

Click the second button (two circles) in the upper-right corner of the editor to display the view and code on both sides

Next will be associated with the control and code, put the mouse on the uitextfield above the CTRL key and drag the mouse to the Viewcontroller.swift file gouges will appear after the following screen to enter the name,

The same method pulls the button over.

Now when the button event is bound, the following screen will appear when you select the buttons and click the first button (arrow) in the top right corner of the editor.

After you move the mouse over the small circle to the right of Touch up InSide, a plus sign appears and then you can bind the method by holding down the left mouse button and dragging to the empty area of the Viewcontroller.swift file, and write a few lines of code in the method body.

@IBAction func btnclicked (sender:anyobject) {

Let Alertview = Uialertview ()//Define a popup box

Alertview.title = "System Info"

Alertview.message = "Your Name is \ (txtname.text)"

Alertview.addbuttonwithtitle ("OK")

Alertview.show ()

}

After running inside the simulator, after entering the name in the text box, click the button effect as shown:

Use Main.storyboard to pull in controls and implement events in Xcode (Swift language)

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.