IOS UI Learning Tutorial Settings Uitextfield various properties _ios

Source: Internet
Author: User
Tags set background

Uitextfield is a very common control used in iOS to receive user input and complete application and user interaction. Its primary properties are set as follows:

Initialize the TextField and set the position and size uitextfield *text = [[Uitextfield alloc]initwithframe:cgrectmake (20, 20, 130, 30)];

 Set the border style, only the settings will show the border style Text.borderstyle = Uitextborderstyleroundedrect;  typedef enum {uitextborderstylenone, Uitextborderstyleline, Uitextborderstylebezel, Uitextborderstyleroundedrect}
 
Uitextborderstyle;
 
Sets the background color of the input box, which is set to white if a custom background picture border is used, it is ignored text.backgroundcolor = [Uicolor Whitecolor];
 
Set Background Text.background = [UIImage imagenamed:@ "Dd.png"];

Set Background Text.disabledbackground = [UIImage imagenamed:@ "Cc.png"];
 
When the input box does not have the content, the watermark prompt content is password text.placeholder = @ "password";
 
Set the font style and size for the contents of the input box Text.font = [Uifont fontwithname:@ ' Arial ' size:20.0f];
 
Set Font Color Text.textcolor = [Uicolor Redcolor];
 
Whether there is a fork in the input box, when the display, for a one-time deletion of the contents of the input box Text.clearbuttonmode = uitextfieldviewmodealways; typedef enum {Uitextfieldviewmodenever, uitextfieldviewmodewhileediting is not present, appears when editing uitextfieldviewmodeunlessediting , uitextfieldviewmodealways appear all the time except for the editor UitexTfieldviewmode;
 
Input box in the beginning of the text Text.text = @ "First in the input box text";
 
Each character is entered into a point term password 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 again to empty text.clearsonbeginediting = YES;
 
Content alignment text.textalignment = Uitextalignmentleft; The vertical alignment of the content Uitextfield inherited from Uicontrol, which has a property contentverticalalignment text.contentverticalalignment =
 
Uicontrolcontentverticalalignmentcenter;
 
When set to YES, the text is automatically scaled to fit the text window size. By default, keep the original size, and let the long text scroll textfied.adjustsfontsizetofitwidth = YES;
 
Set the minimum font size to automatically shrink the display text.minimumfontsize = 20;
 
Set the style of the keyboard text.keyboardtype = Uikeyboardtypenumberpad; typedef enum {Uikeyboardtypedefault, default keyboard, support for all character uikeyboardtypeasciicapable, default keyboard for ASCII Uikeyboardtypenumbersand Punctuation, standard telephone keypad, support +*# character uikeyboardtypeurl, URL keyboard, support. com button only supports URL character Uikeyboardtypenumberpad, digitalKeyboard Uikeyboardtypephonepad, telephone keypad uikeyboardtypenamephonepad, telephone keypad, also support input name uikeyboardtypeemailaddress, keyboard UI for entering e-mail addresses Keyboardtypedecimalpad, numeric keypad has number and decimal point uikeyboardtypetwitter, optimized keyboard, convenient input @, #字符 Uikeyboardtypealphabet = Uikeyboardtypeas
 
Ciicapable,} Uikeyboardtype;
 
Whether the first letter is capitalized text.autocapitalizationtype = Uitextautocapitalizationtypenone;
 typedef enum {Uitextautocapitalizationtypenone, do not automatically capitalize uitextautocapitalizationtypewords, Word first letter uppercase Uitextautocapitalizationtypesentences, the first letter of the sentence is capitalized uitextautocapitalizationtypeallcharacters, all letters are capitalized}
 
Uitextautocapitalizationtype;
 
Return key becomes what key Text.returnkeytype =uireturnkeydone; typedef enum {Uireturnkeydefault, Default Gray button, marked with return Uireturnkeygo, labeled Go Blue button uireturnkeygoogle, labeled Google blue button, language search UI
Returnkeyjoin, the blue button marked with a join Uireturnkeynext, the blue button labeled Next uireturnkeyroute, Route blue Button Uireturnkeysearch, Search blue button uireturnkeysend, labeled Send blue button Uireturnkeyyahoo, marked with Yahoo's blue button Uireturnkeyyahoo, with Yahoo's blue button Uireturnkeye MergeNcycall, emergency call button} Uireturnkeytype;
Keyboard appearance textview.keyboardappearance=uikeyboardappearancedefault typedef enum {uikeyboardappearancedefault, default appearance, light gray

Uikeyboardappearancealert, dark gray graphite color} uireturnkeytype;
 
Set agent to implement protocol text.delegate = self;
 
Add TextField to the view [Self.window Addsubview:text];
 The rightmost plus picture is the following code similar to the 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 keyboard down Becomefirstresponder class to use the Uitextfielddelegate protocol text.delegate = self; Declare the text of the agent is me, I will go to achieve the keyboard down the method of the method in uitextfielddelegate so we have to adopt uitextfielddelegate this Protocol-(BOOL) Textfieldshouldreturn
 :(Uitextfield *) TextField {[text Resignfirstresponder];///main is [receiver Resignfirstresponder] where the call will be able to the receiver corresponding keyboard down
return YES; Override drawing behavior except UitexTfield Object style options, you can also customize the Uitextfield object, add many different rewriting methods for him to change the display behavior of the text field. Each of these methods returns a CGRECT structure that has a boundary range for each part of the text field.
 
The following methods can be overridden.
–textrectforbounds://Rewrite to reset the text area –drawtextinrect://Change the drawing text properties. When overridden, call super can be drawn by default graphic properties, and if you completely rewrite the drawing function, you don't have to call super. –placeholderrectforbounds://Overrides to reset the placeholder area –drawplaceholderinrect://Rewrite to change the drawing placeholder properties. When overridden, call super can be drawn by default graphic properties, and if you completely override the drawing function,
You don't have to call super. –borderrectforbounds://Overrides to reset the Edge area –editingrectforbounds://Rewrite to reset edit area –clearbuttonrectforbounds://rewrite to reset Clearbutto n position, changing size may cause the button's picture distortion –leftviewrectforbounds:–rightviewrectforbounds: Delegate Method-(BOOL) textfieldshouldbeginediting 
:(Uitextfield *) textfield{//Returns a BOOL value specifying whether the progressive text field starts editing return YES; }-(void) textfielddidbeginediting: (Uitextfield *) textfield{//When editing starts, the text field becomes the first responder}-(BOOL) Textfiel Dshouldendediting: (Uitextfield *) textfield{//return bool value, specify whether to allow text fields to end the edit, and when the edit is finished, the text field will yield the top 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 remain active, such as instant message returns no; }-(BOOL) TextfielD: (uitextfield*) TextField Shouldchangecharactersinrange: (nsrange) Range replacementstring: (NSString *) string{// 
This method is invoked when the user uses the AutoCorrect feature to modify the input text to the recommended text.  
This is especially useful for applications that want to join the Undo option//Can track the last changes made in the field, or you can log all edits for audit purposes. 
To prevent text from being changed, you can return no//There is a Nsrange object in the parameter of this method, which indicates the position of the changed text, and the proposed modified text returns YES; }-(BOOL) Textfieldshouldclear: (Uitextfield *) textfield{//Returns a BOOL value indicating whether the content is allowed to be purged based on user requests//can be set to allow scavenging of content under certain conditions retur 
n YES; }-(BOOL) Textfieldshouldreturn: (Uitextfield *) textfield{//Returns a BOOL value indicating whether to allow the end of edit when the ENTER key is pressed///if allowed to call Resignfirstrespon
Der Method, which causes the end of the edit, and the keyboard will be closed [TextField Resignfirstresponder]; 
Check resign the meaning of this word to understand this method of return YES;

 }

The above is the entire content of this article, I hope to learn about the iOS program to help.

Related Article

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.