How to use ios--uitextfiled details
Common methods of Uitextfield
Uitextfield *onetextfield = [[Uitextfield alloc] init];
Most commonly used
Onetextfield.frame = CGRectMake (30, 30, 260, 35); Set Location
Onetextfield.backgroundcolor = [Uicolor Graycolor]; Set Background color
Onetextfield.alpha = 1.0; Set transparency, range from 0.0-1.0
Onetextfield.textcolor = [Uicolor Redcolor]; Set the color of text
Onetextfield.text = @ "Default text"; Set the default text
Onetextfield.placeholder = @ "This is the hint text"; Displays the prompt file, which disappears automatically when you enter text
Onetextfield.font = [Uifont boldsystemfontofsize:25.0f]; Set the size of the font
Onetextfield.textalignment = Nstextalignmentcenter; Set how text is to be
The style for it is as follows
typedef ns_enum (Nsinteger, nstextalignment) {
Nstextalignmentleft = 0,//visually left aligned
#if Target_os_iphone
Nstextalignmentcenter = 1,//visually centered
Nstextalignmentright = 2,//Visually right aligned
#else
Nstextalignmentright = 1,//Visually right aligned
Nstextalignmentcenter = 2,//visually centered
#endif
nstextalignmentjustified = 3,//fully-justified. The last line, a paragraph is natural-aligned.
Nstextalignmentnatural = 4,//indicates the default alignment for script
} ns_enum_available_ios (6_0);
Set the style of Onetextfield
Onetextfield.borderstyle = Uitextborderstyleroundedrect; Set the style of Onetextfield
onetextfield.clearsonbeginediting = YES; Re-edit to empty the original content
Onetextfield.minimumfontsize = 20.0f; Set the minimum font size for auto-shrink display
Onetextfield.tag = 10001; Set the label of the Onetextfield, mainly used in the delegate method
Onetextfield.securetextentry = NO; Sets whether to display as a dot of a password
Onetextfield.autocorrectiontype = YES; Set whether to start the Automatic Reminder update feature
Onetextfield.returnkeytype = Uireturnkeydefault; Set the pop-up keyboard with the button with the Ribbon
The following is the full style with buttons for the keyboard that pops up
typedef ns_enum (Nsinteger, Uireturnkeytype) {
Uireturnkeydefault,//Default style
Uireturnkeygo,//With a Go button
Uireturnkeygoogle,//With a search button, using Google search
Uireturnkeyjoin,//with a join button to log in using
Uireturnkeynext,//with a Next button to enter the next input box
Uireturnkeyroute,//with a route button
Uireturnkeysearch,//with a search button
Uireturnkeysend,//with a Send button
Uireturnkeyyahoo,//Take a search with Yahoo
Uireturnkeydone,//with a done button
Uireturnkeyemergencycall,//With a emergency call button
// };
Onetextfield.keyboardtype = Uikeyboardtypenamephonepad; The style of the keyboard that pops up
The following is the style of all pop-up keyboards
typedef ns_enum (Nsinteger, Uikeyboardtype) {
Uikeyboardtypedefault,//Default type for the current input method.
Uikeyboardtypeasciicapable,//displays a keyboard which can enter ASCII characters, Non-ascii Keyboar DS remain active
Uikeyboardtypenumbersandpunctuation,//Numbers and assorted punctuation.
Uikeyboardtypeurl,//A type optimized for URL entry (shows./. com prominently).
Uikeyboardtypenumberpad,//A number pad (0-9). Suitable for PIN entry.
Uikeyboardtypephonepad,//A phone pad (1-9, *, 0, #, with letters under the numbers).
Uikeyboardtypenamephonepad,//a type optimized for entering a person ' s name or phone number.
Uikeyboardtypeemailaddress,//A type optimized for multiple email address entry (shows space @. Prom inently).
#if __iphone_4_1 <= __iphone_os_version_max_allowed
Uikeyboardtypedecimalpad,//a number pad with a decimal point.
#endif
#if __iphone_5_0 <= __iphone_os_version_max_allowed
Uikeyboardtypetwitter,//A type optimized for Twitter text entry (easy access to @ #)
#endif
//
Uikeyboardtypealphabet = uikeyboardtypeasciicapable,//Deprecated
//
// };
Onetextfield.contentverticalalignment = Uicontrolcontentverticalalignmentcenter; The input to its method
Onetextfield.autoresizingmask = Uiviewautoresizingflexibleheight; Automatic height adjustment
Onetextfield.clearbuttonmode = uitextfieldviewmodewhileediting; Editing will show the deletion of all the small X
Time to delete all small X
typedef enum {
Uitextfieldviewmodenever//heavy does not appear
Uitextfieldviewmodewhileediting,//appears when editing
Uitextfieldviewmodeunlessediting,//appears in addition to editing
Uitextfieldviewmodealways//always appears
} Uitextfieldviewmode;
Whether the first letter is capitalized
Onetextfield.autocapitalizationtype = Uitextautocapitalizationtypenone;
Here are a few cases of uppercase letters
typedef enum {
Uitextautocapitalizationtypenone,//not automatically capitalized
Uitextautocapitalizationtypewords,//capitalize the first letter of the word
Uitextautocapitalizationtypesentences,//capitalize the first letter of the sentence
Uitextautocapitalizationtypeallcharacters,//all letters are capitalized
} Uitextautocapitalizationtype;
Keyboard appearance
Onetextfield.keyboardappearance=uikeyboardappearancealert;
typedef enum {
Uikeyboardappearancedefault,//default appearance, light grey
Uikeyboardappearancealert,//dark grey Graphite
} Uireturnkeytype;
The rightmost plus picture is similar to the left of the following code
Uiimageview *image=[[uiimageview alloc] initwithimage:[uiimage imagenamed:@ "Ic_action_stat_share.png"];
Onetextfield.rightview = image;
Onetextfield.rightviewmode = Uitextfieldviewmodealways;
Onetextfield.leftview = image;
Onetextfield.leftviewmode = Uitextfieldviewmodealways;
typedef enum {
Uitextfieldviewmodenever,
Uitextfieldviewmodewhileediting,
Uitextfieldviewmodeunlessediting,
Uitextfieldviewmodealways
} Uitextfieldviewmode;
To set up a delegate, you need to implement the Protocol, and you need to add the protocol to the. h file
Onetextfield.delegate = self; Set delegate
Add to view and free up memory
[Self.view Addsubview:onetextfield];
[Onetextfield release], Onetextfield = nil;
The method that will be called when you start clicking TextField
-(void) textfielddidbeginediting: (Uitextfield *) TextField {
NSLog (@ "Start editing");
}
The method that is called when the TextField edit ends
-(void) textfielddidendediting: (Uitextfield *) TextField {
NSLog (@ "end edit");
}
Press the call method of the Done button, we make the keyboard disappear
-(BOOL) Textfieldshouldreturn: (Uitextfield *) textfield{
[TextField Resignfirstresponder];
return YES;
}
How to use ios--uitextfiled