Uitextfield usage in iOS

Source: Internet
Author: User

//Initialize TextField and set position and size
Uitextfield *text = [[Uitextfield alloc]initwithframe:cgrectmake (0, 40, 150, 30)];

//Set border style to show border style only if set, otherwise there is no border by default
Text.borderstyle = Uitextborderstyleroundedrect;
typedef enum {
Uitextborderstylenone,
Uitextborderstyleline,
Uitextborderstylebezel,
Uitextborderstyleroundedrect
} Uitextborderstyle;

//Set the background color of the input box, set to white when you use a custom background picture border is ignored
Text.backgroundcolor = [Uicolor Whitecolor];

//Set background picture
Text.background = [UIImage imagenamed:@ "Aa.png"];

//When the input box does not have content, the watermark prompt content is "Please enter password"
Text.placeholder = @ "Please enter password";

Set the input box font style and size

Text.font = [Uifont fontwithname:@ "Arial" size:17.0f];

//Set Font color
Text.textcolor = [Uicolor blackcolor];

If there is a fork in the input box, when it is displayed, it is used to delete the contents of the input box at once
Text.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;

//input box in the beginning of the text
Text.text = @ "Start";

//One character per input becomes point, ciphertext input
Text.securetextentry = YES;

//Whether error correction
Text.autocorrectiontype = Uitextautocorrectiontypeno;

typedef enum {
Uitextautocorrectiontypedefault, default
Uitextautocorrectiontypeno, no automatic error correction
Uitextautocorrectiontypeyes, automatic error correction
} Uitextautocorrectiontype;

Edit it again and empty it
.

text.clearsonbeginediting = YES;

/ /Content Alignment
Text.textalignment = Uitextalignmentright;

//Vertical alignment of content
Text.contentverticalalignment = Uicontrolcontentverticalalignmentcenter;

//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
Textfied.adjustsfontsizetofitwidth = YES;

//Set the minimum font size for the auto-shrink display
Text.minimumfontsize = 20;

//Set the keyboard style
Text.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 initial letter is capitalized
Text.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 into what key
Text.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

Text.delegate = self;

//Add the TextField to the view
[Self.window Addsubview:text];

The rightmost plus picture is similar to the left of the following code

Uiimageview *image=[[uiimageview alloc] initwithimage:[uiimage imagenamed:@ "Right.png"];
Text.rightview=image;
Text.rightviewmode = Uitextfieldviewmodealways;

typedef enum {
Uitextfieldviewmodenever,
Uitextfieldviewmodewhileediting,
Uitextfieldviewmodeunlessediting,
Uitextfieldviewmodealways
} Uitextfieldviewmode;


//Press RETURN key to receive BecomefirstrespondeR

class to adopt the Uitextfielddelegate protocol

Text.delegate = self; Declare the text of the agent is me, I will go to the way to get the keyboard down the method in uitextfielddelegate so we have to use uitextfielddelegate this protocol

-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField
{
[Text Resignfirstresponder]; The main is [receiver Resignfirstresponder] where the call to the receiver corresponding to the keyboard down
return YES;
}


Delegate method

-(BOOL) textfieldshouldbeginediting: (Uitextfield *) textfield{

Returns a bool value that specifies whether the sequential text field begins editing

return YES;
}

-(void) textfielddidbeginediting: (Uitextfield *) textfield{
Triggered when editing is started, the text field becomes first responder
}

-(BOOL) textfieldshouldendediting: (Uitextfield *) textfield{
Returns a bool value that specifies whether the text field is allowed to end editing, 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


return NO;
}

-(BOOL) TextField: (uitextfield*) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *) string{
This method is called when the user uses the AutoCorrect feature to modify the input text to the recommended text.


return YES;
}

-(BOOL) Textfieldshouldclear: (Uitextfield *) textfield{

Returns a bool value indicating whether content is allowed to be purged based on user request
Can be set under certain conditions to allow purging of content

return YES;
}

-(BOOL) Textfieldshouldreturn: (Uitextfield *) textfield{

Returns a bool value that indicates whether the edit is allowed to end when the ENTER key is pressed, which can be used to close the keyboard

return YES;
}

Uitextfield usage in iOS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.