Uitextfield is Uicontrol subclass, Uicontrol is also UIView subclass, so is a view, but more than UIView two functions, 1. Text display, 2. Editing
The use of the process is in four steps:
1. Create an Object
2. Configuration Properties
3 Add to Parent view
4. Release of ownership
1. Create an Object
Uitextfield *text = [[Uitextfield alloc] Initwithframe:cgrectmake (50, 50, 180, 50)]; Text.backgroundcolor = [Uicolor Yellowcolor]; [_view Addsubview:text]; [Text release];
2. Set the text border style (fillet)
Text.borderstyle = Uitextborderstyleroundedrect;
3. Set text default display text (but not as part of text content)
Text.placeholder = @ "Please enter user name";
4. Set text text
Text.text = @ "What tattered";
5. Set the text color
Text.textcolor = [Uicolor blackcolor];
6. Set the alignment of text
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 contents of the box when you start editing
text.clearsonbeginediting = YES;
10. Set the password format (the contents of the input box are displayed as dots)
Text.securetextentry = YES;
11. Set the style of the pop-up keyboard (numeric keypad)
Text.keyboardtype = Uikeyboardtypenumberpad;
12. Lower right corner of keyboard display style
Text.returnkeytype = Uireturnkeygo;
13. Set the Tag value
Text.tag = 120;
14. Keyboard Recycling
1. Click on the lower right corner or enter to recycle the keyboard
1. Setting up the agent
Text.delegate = self;
2. Compliance with the agreement
Add the protocol in the corresponding. h file, such as
@interface Mayappdelegate:uiresponder <UIApplicationDelegate,UITextFieldDelegate>
Obey the,<uitextfielddelegate> agreement
3. Implementing the methods in the Protocol
-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField
{
Recycle keyboard, cancel first responder
[TextField Resignfirstresponder]; return YES;
}
2. Click the empty space to recycle the keyboard
1. Setting up the agent
Text.delegate = self;
2. Compliance with the agreement
Add the protocol in the corresponding. h file, as
@interface Mayappdelegate:uiresponder <UIApplicationDelegate,UITextFieldDelegate>
Obey the,<uitextfielddelegate> agreement
3. Implementing the methods in the Protocol
-(void) touchesended: (Nsset *) touches withevent: (Uievent *) Event {
[Text Resignfirstresponder];
}