IOS UI basics-1.0 Addition Calculator

Source: Internet
Author: User
<span id="Label3"></p>1. Open Xcode and create a new project 2. Single View Application is the best template for Beginners. 3. Fill in the Application Information 4. Build UI interface after the project has been created, automatically helps us to do a lot of configuration, but also automatically generated a lot of files also automatically added to the framework project depends on the development of so many files, which affect the UI interface? Before iOS5, Apple used the Xib file to describe the UI interface, and after iOS5, Apple took a more powerful and advanced storyboard file to describe the interface (Xcode5 is based on iOS7) so It is possible to conclude that modifying the Main.storyboard file in a project modifies the UI Interface. Open Main.storyboard file A look, there is an all-white interface, in fact, This interface is the simulator display interface, the left arrow indicates: the start of the program will show the arrow refers to the Interface. To add other controls to the storyboard interface, show the toolbar: display the control library in nine form, and see more controls at the same Time. From the right, you can see a variety of controls, such as buttons, labels, Text input box and so on 5. left mouse button, Long press A control on the right, you can drag it to the left side of the white interface 6. When you click to select a control, you can change the Control's property 7 in the menu toolbar on the right. set the text output box to enter only numbers and decimal points 8. Run the program can be found, the 9. Listen button Click to open mjviewcontroller.m, Add method declaration in class extension<pre><pre><span style="color: #0000ff;">@interface</span> <span style="color: #000000;">Mjviewcontroller ()</span> <span style="color: #008000;">//</span> <span style="color: #008000;">here first the ibaction is considered void</span>-<span style="color: #000000;"> (ibaction) compute;</span> <span style="color: #0000ff;">@end</span> <span style="color: #0000ff;">@implementation</span> <span style="color: #000000;">mjviewcontroller</span>-(<span style="color: #0000ff;">void</span><span style="color: #000000;">) compute{ NSLog (</span><span style="color: #800000;">@ "</span> <span style="color: #800000;">click the Calculate button</span> <span style="color: #800000;">" </span><span style="color: #000000;">);}</span> <span style="color: #0000ff;">@end</span></pre></pre>next, is to establish the relationship between the button and compute method first click main.storyboard, and then click on the "middle" button now can see the storyboard button and compute method, Next make a connection between Them. hold down the control key, drag the button to the compute method with the left arrow, and then release<p><p>The circle on the left side of the method is filled with a hollow, indicating that a button has been wired</p></p><p><p>In this case, after re-running the program, click the "calculate" button, will automatically call the compute method, the console already has output information</p></p><p><p></p></p>Now can listen to the button click event, Next should be in the Mjviewcontroller compute method to get two text box values, and then display the results to the rightmost text label in the class extension, declare 3 properties, to access the 3 controls in storyboard<pre><pre>@property (nonatomic, weak) iboutlet Uitextfield *<span style="color: #000000;"></span>*<span style="color: #000000;"></span>*result;</pre></pre>Hold down the control key, drag the controls to the corresponding property with the left mouse button, and then release <ul> <ul> <li>The 1th text box can be accessed using the Number1 property of mjviewcontroller;</li> <li>The 2nd text box can be accessed using the Number2 property of mjviewcontroller;</li> <li>Use the Mjviewcontroller Result property to access the text label on the Right.</li> </ul> </ul>Calculates the and of two text boxes in the Compute method and displays the results to the right label<pre><pre>-(<span style="color: #0000ff;">void</span><span style="color: #000000;">) compute{ </span><span style="color: #008000;">//</span> <span style="color: #008000;"> get first value</span> <span style="color: #0000ff;">int</span> num1 =<span style="color: #000000;"> [self.number1.text intvalue]; </span> <span style="color: #008000;">//</span> <span style="color: #008000;">get a second value</span> <span style="color: #0000ff;">int</span> num2 =<span style="color: #000000;"> [self.number2.text intvalue]; </span> <span style="color: #008000;">//</span> <span style="color: #008000;">Set the value</span> of a text label Self.result.text = [nsstring stringwithformat:<span style="color: #800000;">@ "</span><span style="color: #800000;">%d</span><span style="color: #800000;">"</span>, NUM1 +<span style="color: #000000;"> num2];}</span></pre></pre><p><p>OK, you are done! See Effect</p></p><p><p></p></p><p><p>IOS UI basics-1.0 Addition Calculator</p></p></span>

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.