First, Uitextfield
1. What is Uitextfield?
(1) Uitextfield (input box): Controls that control text input and display. In the app, the frequency of Uitextfield appears relatively high;
(2) iOS system with the help of virtual keyboard input, when you click on the input box, the system will automatically bring up the keyboard, so you can further operation. When you do not need to input, you can use the method of recovering the keyboard, the pop-up keyboard;
(3) compared to Uitextfield and Uilabel, Uilabel is mainly used for text display, cannot be edited, Uitextfield allows the user to edit text (input).
2, how to use Uitextfield?
(1) Creating a Uitextfield is similar to the procedure for creating a uilabel.
① opens up space and initializes (if the class has an initialization method, uses its own; otherwise uses the parent class);
② set the text display, input related properties;
③ added to the parent view for display;
④ release.
3. Uitextfield Use 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, Uitextfield more:
(1) The core functions of Uitextfield mainly include 3 aspects:
① text display ② input control ③ appearance configuration
5. Text display:
(1) Uitextfield provides a number of APIs that allow us to control the display of text. Includes font color, alignment, placeholders, and more (see table below)
6. Input control:
(1) The Uitextfield class provides many API for controlling input. Includes password mode, keyboard style, custom keyboard, etc. (see table below)
7. Appearance control:
Uitextfield also provides an API for appearance control. Including border style, clear button, auxiliary view, etc.;
Second, UIButton
1. What is UIButton?
(1) UIButton (button): A control that responds to user clicks. UIButton in the app is a highly-frequent control;
(2) UIButton is different from Uilabel and Uitextfield, focusing on handling the tap. Of course the UIButton class also provides some ways to control the appearance of buttons.
2, how to use UIButton?
(1) Creating UIButton is similar to the steps for creating Uilabel, Uitextfield, UIView.
① Create a Button object (if this class has an initialization method, use its own; otherwise use the parent class);
② Settings button to display related properties;
③ Add a Click event for the button;
④ Add a button to the parent view for display;
The ⑤ button does not need to be freed (because a button created by the class method is used).
3. UIButton Use 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, removing events, and so on.
Note: UIButton:UIControl:UIView (see table below)
5. Appearance control:
(1) UIButton provides an API for appearance control. including title, background map, film, foreground picture, etc. (see table below)
6, subsection:
(1) UIView is the base class for all visual controls;
(2) UILabel, Uitextfield, UIButton are views with specific appearance-specific functions;
(3) Uilabel focuses on the presentation of text;
(4) Uitextfield focus on input;
(5) UIButton focuses on Click event handling.
Third, delegate
1, point return recovery keyboard:
(1) Click the Keyboard return button to achieve the keyboard recycling steps:
① will appdelete as the delegate of Uitextfield;
②appdelete.h file accepts uitextfielddelegate agreement;
③APPDELETE.M File Implementation Textfieldshouldreturn: Method).
2, the keyboard recovery code:
Appdelegate.m
1 -(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField2{3 [TextField Resignfirstresponder]; 4 5 return YES; 6 }
3, subsection:
(1) Uitextfield should not be implemented within the class (. m file) Textfieldshouldreturn: Because sometimes, when we return, we do not always want to recycle the keyboard, for example: There are two input boxes, the first input box is completed, The user points to the return button and moves the cursor to the second input box (that is, the second input box is called the first responder);
(2) For a V, he is only responsible for triggering events, events are implemented by the outside world, that is, delegate.
Iv. iOS Program initiation process
1. The Mian function is the program entry:
(1) Any program, whether based on Mac OS or iOS, is executed starting from the main function of the main.m file.
2, Uiapplicationmain:
(1) Uiapplicationmain is called in the main function of the program entry function, and it realizes 3 functions:
① Creating an Application (uiapplication) instance;
② Creating an application proxy instance;
③ set up the event loop (Runloop: Dead loop, constantly checking the program running state, whether it is touched, shaking, etc.).
3, Uiapplicationmain Analysis:
int Uiapplicationmain ( int argc; Char *argv[]; * principalclassname; *delegateclassname);
(1) Principalclassname: The class name of the Application object (UIApplication or its subclasses);
(2) Delegateclassname: The class name of the application delegate. (Any class that accepts uiapplicationdelegate)! Uiapplicationmain creates an application instance, an application proxy instance, based on the above two class names. The event loop (Runloop) is then established to detect various events of the program (the program starts, receives the touch, and so on).
4. Application Proxy:
(1) Application agent, mainly detects the status of the application and makes corresponding processing;
(2) There are many application states, such as: Program start, enter active state, into the background, memory warning, receive remote messages and so on;
(3) Any object that accepts the Uiapplicationdelegate agreement can become an application proxy;
(4) Once a state of the application is triggered, the appropriate proxy method is executed.
5, Uiapplicationdelegate:
Uiapplicationdelegate is an OC protocol. It declares a bunch of methods that are related to the running state of the application and are implemented by the application proxy. The UIApplication object is responsible for invocation. (see table below)
6, UIWindow:
(1) UIWindow as the application window, when the application starts to load, the various UI interface is the use of window to render;
(2) UIWindow should be as large as the screen when it is created. The screen size can be obtained by [UIScreen Mainscreen].bounds;
(3) [Self.window makekeyandvisible];//Let window become visible, that is, the window is displayed.
V. Summary
(1) UILabel, Uitextfield, UIButton are the most commonly used controls;
(2) They are directly or indirectly inherited from the UIView, but the appearance and function are different;
(3) familiar with the characteristics and methods of various controls is our late-stage project protection;
(4) delegate is an important design mode of iOS, understand its principle, help write high-quality code;
(5) The main function is the entrance to the program. The Uiapplicationmain function creates an application instance, an application proxy instance, and an event loop.
Six, the next one will continue to update the supporting knowledge point practice;
Email:[email protected]
iOS development-ui from getting started to mastering (iv)