IOS development-UI from entry to entry (4), ios-ui

Source: Internet
Author: User
Tags uicontrol

IOS development-UI from entry to entry (4), ios-ui

I. UITextField

1. What is UITextField?

(1) UITextField (input box): Controls text input and display. UITextField appears frequently in the App;

(2) iOS uses a virtual keyboard for input. When you click the input box, the system automatically calls up the keyboard for further operations. When you do not need to enter the keyboard, you can use the keyboard revocation method to retrieve the pop-up keyboard;

(3) compared with UILabel, UILabel is mainly used for text display and cannot be edited. UITextField allows users to edit text (input ).

2. How to Use UITextField?

(1) creating UITextField is similar to creating UILabel.

① Open up space and initialize (if this class has an initialization method, use your own; otherwise, use the parent class );

② Set text display and input related attributes;

③ Add it to the parent view for display;

④ Release.

3. UITextField example:

UITextField * userNameTextField = [[UITextField alloc] initWithFrame: CGRectMake (100,100,190, 30)];

UserNameTextField. borderStyle = UITextBorderStyleRoundedRect;

UserNameTextField. placeholder = @ "mobile phone number/mailbox ";

[ContainerView addSubview: userNameTextField];

[UserNameTextField release];

4. More UITextField:

(1) UITextField core functions mainly include three aspects:

① Text display ② input control ③ appearance Configuration

5. text display:

(1) UITextField provides many APIs to control text display. Including font color, alignment, and placeholders (see the table below)

  

6. input control:

(1) The UITextField class provides many APIs for controlling input. Including password mode, keyboard style, and custom keyboard (see the table below)

  

7. Appearance Control:

UITextField also provides APIs for visual control. Including border style, Clear button, and secondary view;

  

Ii. UIButton

1. What is UIButton?

(1) UIButton (button): a control that responds to user clicks. In the App, UIButton is a frequently-occurring control;

(2) UIButton and UILabel and UITextField have different focuses on processing points. Of course, the UIButton class also provides some methods to control the button appearance.

2. How to Use UIButton?

(1) creating UIButton is similar to creating UILabel, UITextField, and UIView.

① Create a button object (if this class has an initialization method, use your own; otherwise, use the parent class );

② Set the button to display relevant properties;

③ Add a click event for the button;

④ Add a button to the parent view for display;

⑤ The button does not need to be released (because the button created by the class method is used ).

3. UIButton example:

UIButton * loginButton = [UIButton buttonWithType: UIButtonTypeSystem];

LoginButton. frame = CGRectMake (30,200, 60, 30 );

[LoginButton setTitle: @ "login" forState: UIControlStateNormal];

[LoginButton addTarget: self action: @ selector (login :) forControlEvents: UIControlEventTouchUpInside];

[ContainerView addSubview: loginButton];

4. UIButton add event:

(1) UIButton inherits control-related methods from the parent class UIControl, such as adding events and removing events.

Note: UIButton: UIControl: UIView (see the table below)

  

5. Appearance Control:

(1) UIButton provides APIs for visual control. Including titles, background images, and foreground images (see the table below)

  

  

6. Section:

(1) UIView is the base class of all visual controls;

(2) UILabel, UITextField, and UIButton are views with specific functions;

(3) UILabel focuses on text presentation;

(4) UITextField focuses on input;

(5) UIButton focuses on processing click events.

3. delegate

1. Click return to recycle the keyboard:

(1) Click the return button on the keyboard to recycle the keyboard:

① Use AppDelete as the delegate of UITextField;

② AppDelete. h file accepted the UITextFieldDelegate protocol;

③ Implement textFieldShouldReturn in the AppDelete. m file: method ).

2. keyboard recycling code:

AppDelegate. m

1 - (BOOL)textFieldShouldReturn:(UITextField *)textField2 {3     [textField resignFirstResponder];4 5     return YES;6 }

3. Section:

(1) UITextField should not be inside the class (. m file) Implement textFieldShouldReturn: Sometimes, when we click return, we do not always want to recycle the keyboard. For example, there are two input boxes. After the first input box is complete, the user clicks return, move the cursor to the second input box (that is, the second input box is called the first responder );

(2) For a V, it is only responsible for triggering the event, and the event is implemented by the outside, that is, delegate.

4. iOS program Startup Process

1. The mian function is the program entry:

(1) Any program, whether based on Mac OS or iOS, is executed from the main function of the main. m file.

2. UIApplicationMain:

(1) UIApplicationMain is called in the main function of the program entry function. It mainly implements three functions:

① Create an application (UIApplication) instance;

② Create an application proxy instance;

③ Create an event loop (runloop: an endless loop that constantly checks the running status, whether the program is touched or shaken ).

3. Analysis of UIApplicationMain:

int UIApplicationMain (   int argc;   char *argv[];   NSString *principalClassName;   NSString *delegateClassName);

(1) principalClassName: Class Name of the Application Object (UIApplication or its subclass );

(2) delegateClassName: The Class Name of the application delegate. (Any class that accepts UIApplicationDelegate )! UIApplicationMain creates an application instance and an application proxy instance based on the preceding two class names. Then, create a runloop to detect various events of the program (the program starts to start, receives touch, and so on ).

4. Application Proxy:

(1) The application proxy mainly checks the status of the application and processes it accordingly;

(2) There are many application states, such as program startup, active, going to the background, memory warning, and receiving Remote Messages;

(3) Any object that accepts the UIApplicationDelegate protocol can become an application proxy;

(4) Once an application is triggered in a certain state, the corresponding proxy method will be executed.

5. UIApplicationDelegate:

UIApplicationDelegate is an OC protocol. A bunch of methods are declared. These methods are related to the application running status, which is implemented by the application proxy. The UIApplication object is called. (See the table below)

  

6. UIWindow:

(1) As the application window, UIWindow is loaded when the application starts, and various UI interfaces are presented by window;

(2) When creating a UIWindow, it should be as big as the screen. [UIScreen mainScreen]. bounds can be used to obtain the screen size;

(3) [self. window makeKeyAndVisible]; // display a window.

V. Summary

(1) UILabel, UITextField, and UIButton are commonly used controls;

(2) They both inherit from UIView directly or indirectly, but their appearances and functions are different;

(3) familiarity with the features and methods of various controls is the protection of projects in the future;

(4) delegate is an important design pattern for iOS. understanding its principles helps to write high-quality code;

(5) The main function is the entry of the program. The UIApplicationMain function creates an application instance and uses a program proxy instance to create an event loop.

6. the next article will continuously update related knowledge point exercises;

Email: dingding3w@126.com

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.