I. Overview of Uitextfield
1.Uitextfield( text input box ): controls the control of this input and display.
2.iOS system with the use of virtual keyboard input , when the click on the box system will automatically bring up the keyboard to facilitate your further operation, you can use the method of recovering the keyboard when you do not need to input, retract the pop-up keyboard.
Compared to 3.UITextField and Uilabel, Uilabel is mainly used for text display, cannot be edited, Uitextfield allows the user to edit text (input).
Ii. creation of Uitextfield
1. Creating a Uitextfield is similar to the steps for creating a Uilabel:?
(1) Open space and initialize (if this class has initialization? method, make it own, otherwise use the parent class).?
(2) Set the text display, input related properties?.
(3) Added to the parent view for display.
(4) Release object (MRC).
2. code example:
1 Uitextfield *usernametextfield = [[Uitextfield alloc]initwithframe:cgrectmake] - )]; 2 Usernametextfield.borderstyle =uitextborderstyleroundedrect; 3 @" mobile phone number/email " 4 [Containerview Addsubview:usernametextfield]; 5 [Usernametextfield release];
Third, attribute
1. Enter the text from the beginning of the box
Textfield.text = @ "input box in the beginning of the text";
2. Color of this content
Textfield.textcolor = [Uicolor Redcolor];
3. The alignment of this (horizontal direction)
Textfield.textalignment = Nstextalignmentleft;
4. Set the font style and size of the input box contents
Textfield.font = [Uifont fontwithname:@ "helvetica-bold" size:]; // Bold in bold, 20th words.
5. Placeholder string (without any input, the hint string given)
Textfield.placeholder = @ "Please enter user name";
6. Whether to allow input
1 textfield.enabled =no; // do not allow input, do not eject the keyboard ? 2 textfield.enabled =yes; // the default is yes. Allow input
7 If you want to start typing, empty the contents of the input box
1 textfield.clearsonbeginediting = YES; // Clear 2 textfield.clearsonbeginediting = NO; // do not empty
8. Does the text display in dots format?
1 textfield.securetextentry = YES; // Password Mode 2 textfield.securetextentry = NO; // Normal mode ?
9. Type of pop-up keyboard (enumeration value)
// Numeric Keypad
10. The return button type (enumeration value) in the lower right corner of the keyboard
Textfield.returnkeytype = Uireturnkeynext;
11. Custom Input View (default is keyboard)
Textfield.inputview = Myinputview;
12. Enter the secondary view above the view (default nil)
Textfield.inputaccessoryview = Myaccessoryview;
13. Border Style (enumeration value), only set to display border style
Textfield.borderstyle = Uitextborderstyleroundedrect;
14. Clear button Mode (enumeration value)
// always show? Clear Button
15. Left view of the input box
Textfield.leftview = Leftview;
16. Display mode for left view
// always show left view
17. Right view of the input box
Textfield.rightview = Rightview;
18. The display mode of the right view
Textfield.rightviewmode = Uitextfieldviewmodealways;
19. Set whether the text automatically adapts to the window size
Textfied.adjustsfontsizetofitwidth = YES; // when set to Yes, the text automatically shrinks to fit the text window size. The default is to keep the original size and let long text scroll
20. Set the minimum font size for auto-shrink display
;
21. Set the background color of the input box
Textfield.backgroundcolor = [Uicolor Whitecolor];
22. Set the background, if you use a custom background picture, the border will be ignored
Textfield.background = [UIImage imagenamed:@ "dd.png"];
23. Whether error correction
Textfield.autocorrectiontype = Uitextautocorrectiontypeno;
24. Keyboard appearance (enumeration values)
Textview.keyboardappearance=uikeyboardappearancealer;// dark grey Graphite
25. Whether the initial letter is capitalized
Text.autocapitalizationtype = Uitextautocapitalizationtypenone;
26. Vertical alignment of content Uitextfield inherits from Uicontrol, which has an attribute in this class contentverticalalignment
Text.contentverticalalignment = Uicontrolcontentverticalalignmentcenter;
Three, Agent method (all is TextField beginning)
1. Returns a bool value that specifies whether the text field is allowed to start editing
1 -(BOOL) textfieldshouldbeginediting: (Uitextfield *) textfield{ 2 return YES; 3 }
2. When you start editing, the method is triggered and the text field becomes first responder
1 -(void) textfielddidbeginediting: (Uitextfield *) textfield{ 2 }
3. Returns the bool value, specifies whether the text field is allowed to end the edit, and when the edit is finished, the text field yields first responder, to prevent the text field from disappearing when the user finishes editing, to return no, which is useful for programs where text fields must always remain active. Like instant Messaging.
1 -(BOOL) textfieldshouldendediting: (Uitextfield *) textfield{ 2 return NO; 3 }
4. End edit Triggers the method
1 -(void) textfielddidendediting: (Uitextfield *) textfield{2 }
5. This method is called when the user uses the auto-correction function to modify the input text to the recommended text, which is especially useful for applications that want to join the Undo option.
1 -(BOOL) TextField: (uitextfield*) TextField Shouldchangecharactersinrange: (nsrange) Range Replacementstring: (NSString *) string{ 2 3/// can track the last modification made in the field, You can also log all edits and use them for auditing purposes. 4 // to prevent text from being changed, you can return no 5 // There is a Nsrange object in the parameter of this method, which indicates the position of the changed text, and the suggested text is in it. 6 return YES; 7 }
6. Returns a bool value that specifies whether to allow content to be purged based on user requests, which can be set under certain conditions to allow purging of content
1 -(BOOL) Textfieldshouldclear: (Uitextfield *) textfield{ 2 return YES; 3
7. Returns a bool value that specifies whether the edit is allowed to end when the ENTER key is pressed, which is triggered when the return button is clicked in the lower-right corner, and if the Resignfirstresponder method is called, this results in the end of the edit and the keyboard is closed [TextField Resignfirstresponder];
1 -(BOOL) Textfieldshouldreturn: (Uitextfield *) textfield{ 2 return YES; 3 }
"Ios-develop User interaction-04" Uitextfield