Initialize TextField and set location and size
Uitextfield *textfield = [[Uitextfield alloc]initwithframe:cgrectmake (20, 20, 130, 30)];
Set border style to show border style only if set
Textfield.borderstyle = Uitextborderstyleroundedrect;
typedef enum {
Uitextborderstylenone,
Uitextborderstyleline,
Uitextborderstylebezel,
Uitextborderstyleroundedrect
} Uitextborderstyle;
Sets the background color of the input box, which is set to white if you use a custom background picture border is ignored
Textfield.backgroundcolor = [Uicolor Whitecolor];
Set background
Textfield.background = [UIImage imagenamed:@ "Dd.png"];
Set background
Textfield.disabledbackground = [UIImage imagenamed:@ "Cc.png"];
When the input box does not have content, the watermark prompt content is password
Textfield.placeholder = @ "password";
Set font style and size for input box contents
Textfield.font = [Uifont fontwithname:@ "Arial" size:20.0f];
Set Font Color
Textfield.textcolor = [Uicolor Redcolor];
Whether there is a fork in the input box, when it appears, to delete the contents of the input box at once
Textfield.clearbuttonmode = Uitextfieldviewmodealways;
typedef enum {
Uitextfieldviewmodenever, the heavy does not appear
Uitextfieldviewmodewhileediting, appearing when editing
Uitextfieldviewmodeunlessediting, except for the editor's appearance.
Uitextfieldviewmodealways always appears.
} Uitextfieldviewmode;
Enter the text from the beginning of the box
Textfield.text = @ "The beginning of the text in the input box";
Every character you enter becomes a point. Password input
Textfield.securetextentry = YES;
Whether to correct
Textfield.autocorrectiontype = Uitextautocorrectiontypeno;
typedef enum {
Uitextautocorrectiontypedefault, default
Uitextautocorrectiontypeno, no automatic error correction
Uitextautocorrectiontypeyes, automatic error correction
} Uitextautocorrectiontype;
Edit it again and empty it.
textfield.clearsonbeginediting = YES;
Content Alignment
Textfield.textalignment = Uitextalignmentleft;
The vertical alignment of content Uitextfield inherits from Uicontrol, which has an attribute in this class contentverticalalignment
Textfield.contentverticalalignment = Uicontrolcontentverticalalignmentcenter;
When set to Yes, the text automatically shrinks to fit the text window size. The default is to keep the original size and let long text scroll
Textfield.adjustsfontsizetofitwidth = YES;
Set the minimum font size for auto-shrink display
Textfield.minimumfontsize = 20;
Set the keyboard style
Textfield.keyboardtype = Uikeyboardtypenumberpad;
typedef enum {
Uikeyboardtypedefault, default keyboard, all characters supported
Uikeyboardtypeasciicapable, default keyboard that supports ASCII
Uikeyboardtypenumbersandpunctuation, standard telephone keypad, supports +*# characters
Uikeyboardtypeurl, URL keyboard, support for. com buttons only support URL characters
Uikeyboardtypenumberpad, Digital keypad
Uikeyboardtypephonepad, telephone keypad
Uikeyboardtypenamephonepad, telephone keypad, also support input person name
Uikeyboardtypeemailaddress, keyboard for entering e-mail addresses
Uikeyboardtypedecimalpad, numeric keypad with numbers and decimal points
Uikeyboardtypetwitter, optimized keyboard for easy input @, #字符
Uikeyboardtypealphabet = uikeyboardtypeasciicapable,
} Uikeyboardtype;
Whether the first letter is capitalized
Textfield.autocapitalizationtype = Uitextautocapitalizationtypenone;
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;
Return key becomes what key
Textfield.returnkeytype =uireturnkeydone;
typedef enum {
Uireturnkeydefault, default Gray button, marked with return
Uireturnkeygo, the blue button labeled Go
Uireturnkeygoogle, a blue button labeled Google, search by language
Uireturnkeyjoin, blue button labeled Join
Uireturnkeynext, the blue button labeled next.
Uireturnkeyroute, a blue button labeled route
Uireturnkeysearch, the blue button labeled Search
Uireturnkeysend, the blue button labeled Send
Uireturnkeyyahoo, the blue button labeled Yahoo!
Uireturnkeyyahoo, the blue button labeled Yahoo!
Uireturnkeyemergencycall, emergency call button
} Uireturnkeytype;
Keyboard appearance
Textview.keyboardappearance=uikeyboardappearancedefault;
typedef enum {
Uikeyboardappearancedefault, default appearance, light grey
Uikeyboardappearancealert, dark grey graphite
} Uireturnkeytype;
Setting up proxies for implementing protocols
Textfield.delegate = self;
Add the TextField to the view
[Self.window Addsubview:
Uitextfile Attribute Method Daquan