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: