Uitextfield is a subclass of uicontrol, and uicontrol is a subclass of uiview, so it is also a view, but there are two more functions than uiview, 1. text display, 2. text editing
The procedure is as follows:
1. Create an object
2. Configure attributes
3 add to parent View
4. Release ownership
1. Create an object
Uitextfield * text = [[uitextfieldalloc] initwithframe: cgrectmake (,)]; text. backgroundcolor = [uicoloryellowcolor]; [_ viewaddsubview: text]; [textrelease];
2. Set the border style (rounded corner) of Text)
Text. borderstyle = uitextborderstyleroundedrect;
3. Set text to display text by default (but not as part of text content)
Text. placeholder = @ "Enter the user name ";
4. Set text
Text. Text = @ "What is broken ";
5. set text color
Text. textcolor = [uicolorblackcolor];
6. set text alignment
Text. textalignment = nstextalignmentcenter;
7. set text font
Text. font = [uifont systemfontofsize: 18];
8. Set whether the input box can be edited.
Text. Enabled = yes;
9. Set whether to clear the content in the box when editing starts.
Text. clearsonbeginediting = yes;
10. Set the password format (whether the content in the input box is displayed as a dot)
Text. securetextentry = yes;
11. Set the pop-up keyboard style (numeric keyboard)
Text. keyboardtype = uikeyboardtypenumberpad;
12. display style in the lower right corner of the keyboard
Text. returnkeytype = uireturnkeygo;
13. Set the tag Value
Text. Tag = 120;
14. keyboard recycling
1. Click the lower right corner or press enter to recycle the keyboard.
1. Set proxy
Text. Delegate = self;
2. Obey the agreement
Add the protocol to the corresponding. h file, as shown in figure
@ Interface mayappdelegate: uiresponder <uiapplicationdelegate, uitextfielddelegate>
Obey, <uitextfielddelegate> Protocol
3. Methods in the Implementation Protocol
-(Bool) textfieldshouldreturn :( uitextfield *) textfield
{
Reclaim the keyboard and cancel the first responder
[Textfield resignfirstresponder]; returnyes;
}
2. Click the blank space to clear the keyboard
1. Set proxy
Text. Delegate = self;
2. Obey the agreement
Add the protocol to the corresponding. h file, as shown in figure
@ Interface mayappdelegate: uiresponder <uiapplicationdelegate, uitextfielddelegate>
Obey, <uitextfielddelegate> Protocol
3. Methods in the Implementation Protocol
-(Void) touchesended :( nsset *) touches withevent :( uievent *) event {
[Text resignfirstresponder];
}
Uitextfield common attributes and keyboard for uitextfield Revocation