Uitextfield commonly used for external text input, is a common input box. The following code details the various properties and methods of Uitextfield
-(void) viewdidload{ [Super viewdidload]; //Text input box uitextfield Uitextfield * TextField = [[Uitextfield alloc] init]; //settings Textfield.frame = CGRectMake ((a); &nbs p; //Set the text in the input box to default to null Textfield.text = nil; //Set the property string in the input box, default is NULL if the property is not understood String, can skip Textfield.attributedtext = nil; //Set default property string Textfield.defaulttextattributes = nil; //Set the default displayed property string Textfield.attributedplaceholder = nil; //Set the text color of the input box, default is blank, not set because the system is set to black Textfield.textcolor = [Uicolor blackcolor]; // Set the background color Textfield.backgroundcolor = [Uicolor greencolor]; //Set the font of the input box, default is empty, not set, system default setting 12pt Textfield.font = [Uifont systemfontofsize:18.0]; //Set background image Valid only if the frame type is set to Uitextborderstylenone //textfield.background = [UIImage imagenamed:@ "1.png"];&nbsP //textfield.disabledbackground = [UIImage imagenamed:@ "2.png"]; //Set input box to Password box Every character you enter becomes a point textfield.securetextentry = no; /* typedef ns_enum ( Nsinteger, nstextalignment) { nstextalignmentleft = 0, & nbsp //Align Left #if iphone nstextalignmentcenter = 1, Center nstextalignmentright = 2, //Right align #else ipad& nbsp; nstextalignmentright = 1, //Visually right aligned Nstex talignmentcenter = 2, //visually centered #endif other   ; nstextalignmentjustified = 3, //and paragraph alignment nstextalignmentnatural = 4, // Default status Normal   } ns_enum_available_ios (6_0); */ //Set the text display mode of the input box Textfield.textalignment = nstextalignmentnatural; //Set text displayed by default 70% transparency Textfield.placeholder = @ "Please enter text"; /*& nbsp; typedef ns_enum (Nsinteger, Uitextborderstyle) { Uitextborderstylenone, & nbsp /No Border Uitextborderstyleline, //square Rectangle solid line uitextborderstylebezel, /square Rectangle solid line uitextborderstyleroundedrect//rounded rectangle with transparent lines & nbsp; };*/ /Set Frame type Textfield.borderstyle = uitextborderstylenone; & nbsp; //Set input box font minimum textfield.minimumfontsize = 18.0; // When set to Yes, the text automatically shrinks to fit the text window size, and the default is to keep the original size, while the long text scrolls Textfield.adjustsfontsizetofitwidth = no; /* Ypedef ns_enum (Nsinteger, uikeyboardtype) {&NBsp; uikeyboardtypedefault, //default status, all characters are supported Uikeyboardtypeasciicapable, //Can input ASCII code Uikeyboardtypenum bersandpunctuation, //Digital and punctuation uikeyboardtypeurl, & nbsp //letters and URLs (COM) uikeyboardtypenumberpad, & nbsp Digital keypad Uikeyboardtypephonepad, //digital with +*# telephone keypad  &N Bsp Uikeyboardtypenamephonepad, //telephone keypad support input person name Uikeyboardtypeemailaddress, //Alphabet with @. Enter email Uikeyboardtypedecimalpad Ns_enum_available_ios (4_1), //numeric keypad with . Uikeyboardtypetwitter Ns_enum_available_ios (5_0), //letter with @# Uikeyboardtypewebsearch Ns_enum_available_ios (7_0), //Letter Belt Go button Uikeyboardtypealphabet = uikeyboardtypeasciicapable,//You can enter ASCII First capital letters }; */ //Set keyboard style Textfield.keyboardtype = uikeyboardtypeurl; // When you edit the input box again, the contents of the input box are emptied textfield.clearsonbeginediting = no; //Whether the first letter is capitalized /* typedef ns_enum (Nsinteger, Uitextautocapitalizationtype) { uitextautocapitalizationtypenone, //all lowercase Uitextautocapitalizationtypewords, //capitalize the first letter of each word (with spaces in the middle) Uitextautocapitalizationtypesentences, //initial capitalization of the first word Uitextautocapitalizationtypeallcharacters,//ALL caps }; */ Textfield.autocapitalizationtype = Uitextautocapitalizationtypenone; /* The input box has a fork number, when it is displayed, used to delete the inside of the input box once typedef ns_enum (Nsinteger, Uitextfieldviewmode) { Uitextfieldviewmodenever, //default display no uitextfieldviewmodewhileediting, //input with cross number uitextfieldviewmodeunlessediting,//no cross when input Uitextfieldviewmodealways //Always show forks, }; */ Textfield.clearbuttonmode = uitextfieldviewmodewhileediting; /* & nbsp typedef enum { Uitextautocorrectiontypedefault, default Uitextautocorrectiontypeno, & nbsp No automatic error correction uitextautocorrectiontypeyes, automatic error correction } Uitextautocorrectiontype; */ //Whether error correction Textfield.autocorrectiontype = Uitextautocorrectiontypeno; /* typedef ns_enum (Nsinteger, Uireturnkeytype) { Uireturnkeydefault, //return key display default status return uireturnkeygo, //return key display go Uireturnkeygoogle, //return key display search uireturnkeyjoin, //ret Urn Key display join uireturnkeynext, //return key show next Next & nbsp Uireturnkeyroute, //return key display route uireturnkeysearch, //return key display search uireturnkeysend, //return key display send Send Uireturnkeyyahoo, //return key display search uireturnkeydone, //return built done   uireturnkeyemergencycall, }; */ //Set the return key type Textfield.returnkeytype = uireturnkeydefault; /* typedef ns_enum ( Nsinteger, uikeyboardappearance) { uikeyboardappearancedefault, // Default appearance light grey uikeyboardappearancedark //dark grey graphite Uikeyboardappearancelight //light gray Uikeyboardappearance Alert = uikeyboardappearancedark, //dark grey graphite }; */ //Set the appearance of the keyboard   ; Textfield.keyboardappearance = uikeyboardappearancedefault; //Set the view of the position between input text Uiimageview *image = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:@ "1"]]; Image.bounds = CGRectMake (0, 0, ten, ten); TEXtfield.leftview = image; //display status and cross-sign display status similar to Textfield.leftviewmode = Uitextfieldviewmodealways ; //Set view Uiimageview *image1 = [[Uiimageview alloc] Initwithimage:[uiimage of the right position inside the input box imagenamed:@ "2"]]; image1.bounds = CGRectMake (0, 0, ten); Textfield.rightview = image1;  ; //Display status and cross-sign display status similar to Textfield.rightviewmode = uitextfieldviewmodealways; & nbsp Textfield.delegate = self; [Self.view Addsubview:textfield];} /* Override drawing of various methods //override to reset the Edge area -(CGRect) Borderrectforbounds: (cgrect) bounds; //rewrite to reset the text area -(CGRect) Textrectforbounds: (cgrect) bounds; //rewrite to reset the placeholder area is also the default display area -(cgrect) Placeholderrectforbounds: (cgrect) bounds; //rewrite to reset the editing area -(CGRect) Editingrectforbounds: (CGRect) bounds; //rewrite to reset the Clearbutton position, changing the size may cause the picture of the button to distort -(CGRect) Clearbuttonrectforbounds: (CGRect) Bounds; //rewrite to reset the left view area -(CGRect) Leftviewrectforbounds: (CGRect) bounds; // Rewrite to reset the right view area -(CGRect) Rightviewrectforbounds: (cgrect) bounds; //rewrite paint to change text properties, When overriding call super can be drawn by default graphics properties, if you completely override the drawing function, you do not have to call super -(void) Drawtextinrect: (cgrect) rect; //override draw Change placeholder properties , the call to super When overridden can be drawn by default drawing properties, and if you completely override the drawing function, you do not have to call super -(void) Drawplaceholderinrect: (cgrect) rect; */#pragma mark-uitextfielddelegate//Set the input box, whether it can be modified/no will not be modified, no keyboard//Yes can be modified, the default value-(BOOL) Textfieldshouldbeginediting: ( Uitextfield *) textfield{ return YES; When you start editing with focus, the method is executed-(void) textfielddidbeginediting: (Uitextfield *) textfield{}/* returns a bool value that specifies whether the text field is allowed to touch, and when the edit is finished, The text field will yield first responder to prevent the text field from disappearing when the user finishes editing, you can return no this is useful for programs where text fields must always be active, such as if the message */-(BOOL) Textfieldshouldendediting: (Uitextfield *) textfield{ return NO;} When the text box finishes editing, it calls-(void) textfielddidendediting: (Uitextfield *) textfield{}/* when the user uses the AutoCorrect feature to modify the input text to the recommended text, This method is called This is for applications that want to add the Undo optionOrder is particularly useful can track the last modification made in a field, or log records of all edits, used for auditing purposes to prevent the text from being changed can return no the method's parameters in another Nsrange object, indicating the position of the changed text, The proposed modified text is also */-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) Range Replacementstring: (NSString *) string{ return YES;} Returns a BOOL value indicating whether to allow content to be purged based on user request//can be set under certain conditions to allow purging of content-(BOOL) Textfieldshouldclear: (Uitextfield *) textfield{ return YES;} Returns a BOOL value that indicates whether the edit is allowed to end when the ENTER key is pressed//if allowing the Resignfirstresponder method to be called will result in the end of the edit, and the keyboard will be lucky-(BOOL) Textfieldshouldreturn: ( Uitextfield *) textfield{ return YES;
iOS Foundation-uitextfield