One, Uitextfield manually write controls
Uitextfield *txtaccount = [[uitextfield alloc] initwithframe:cgrectmake (ten, ten,+) ];
// set up delegates
[Txtaccount setdelegate:Self];
// Set placeholder
[Txtaccount setplaceholder:@ " account "];
// set color
[Txtaccount setvalue:[uicolor Redcolor] forkeypath:@ "_placeholderlabel.textcolor"];
// Set Font
[Txtaccount setvalue:[uifont boldsystemfontofsize:16] forkeypath:@ "_placeholderlabel.font"];
// Set text alignment
[Txtaccount settextalignment:nstextalignmentleft];
// set style
[Txtaccount setborderstyle:uitextborderstyleroundedrect];
// join the view
[Self. View addsubview: Txtaccount];
[Txtaccount release];
Second,uitextfielddelegate entrusted
// Set input box, whether can be modified
//no- cannot be modified, keyboard not present
//yes- can be modified, default value
-(BOOL) textfieldshouldbeginediting: (uitextfield *) textfield{
return YES;
}
The method is executed when you click the back key of the keyboard (lower-right corner).
// commonly used to hide the keyboard
-(BOOL) Textfieldshouldreturn: (uitextfield *) textfield{
if (txtaccount = = TextField) {
[txtaccount resignfirstresponder];
}
return YES;
}
The method is executed when the input box gets the focus.
-(void) textfielddidbeginediting: (uitextfield *) textfield{
NSLog(@ "textfielddidbeginediting");
}
// Specify whether to allow text fields to end edit, allow text fields to lose first responder
-(BOOL) textfieldshouldendediting: (uitextfield *) textfield{
return YES;
}
// text box when you lose first responder, execute
-(void) textfielddidendediting: (uitextfield *) textfield{
NSLog(@ "textfielddidendediting");
}
// indicates whether to allow content to be purged based on user requests
-(BOOL) textfieldshouldclear: (uitextfield *) textfield{
NSLog(@ "textfielddidendediting");
return YES;
}
// text box text, whether it can be modified
-(BOOL) TextField: (uitextfield *) TextField shouldchangecharactersinrange: (nsrange) Range replacementstring: (nsstring *) string{
return YES;
}
Uitextfield Manual Writing