In XCODE, use Main. Storyboard to pull the control and implement events (Swift language). xcodestoryboard tutorial

Source: Internet
Author: User

In XCODE, use Main. Storyboard to pull the control and implement events (Swift language). xcodestoryboard tutorial

In XCODE, how does one pull the control in Main. Storyboard and implement a simple effect? I have just been familiar with the Swift language, and I am still unfamiliar with IDE operations. If I don't understand it, I will refer to my previous articles on the Internet. Below I will demonstrate how to use the Swift language with Main. Storyboard to demonstrate a small example. I will not talk about creating a SingleView Application here.

The created application has automatically created a ViewController connected to Main. Storyboard.

Next, add UITextField and UIButton to the View in Main. Storyboard, and double-click UIButton to modify the text content.

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

Next, we will associate the controls and code, place the mouse over UITextField, press Ctrl, and drag the mouse to the blank area of the ViewController. swift file. Then, the following screen appears and enter NAME,

In the same way, pull the button.

Now, when you bind a button event, select the button and click the last button (arrow) in the second row in the upper right corner of the editor to display the following picture.

Move the mouse to the circle on the right of "Touch Up InSide", a plus sign will appear, and hold down the left mouse button and drag it to ViewController. after the blank area of the swift file, you can bind the method and write several lines of code in the method body.

@ IBAction func btnClicked (sender: AnyObject ){

Let alertView = UIAlertView () // define a pop-up box

AlertView. title = "System Info"

AlertView. message = "Your Name is \ (txtName. text )"

AlertView. addButtonWithTitle ("OK ")

AlertView. show ()

}

 

After running in the simulator (command + R shortcut), enter a name in the text box and click the button, as shown in:

 

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.