"iOS Dev-15" Uitextfield Common Properties: text box style, text style, keyboard style, left and right view style, clear button settings, etc.

Source: Internet
Author: User

(1) You can set the style of the text box (including shape, border color, background, etc.) as needed.


(2) You can set the text display style according to the need (including the ciphertext display when the password is entered, the text is centered horizontally, the vertical center is up and down, whether the text entered is the chief wood capitalization, whether the text shrinks or scrolls to the right, etc.).


(3) You can set a variety of keyboard styles as needed (only numbers, letters, etc.).


(4) There are Inputview can pop up a view, used to replace the pop-up keyboard, temporarily do not know what is the use, but it seems to be able to use a lot of places AH.


(5) Return style settings, can be set to Google can also be set to go and search and other more image buttons.


(6) There is also a clearsonbeginediting whether setting the Clear button is also very common.


(7) Also useful more than the estimate is the left and right view, that is, our common user name and password in front of a small icon to indicate the user's "villain" and the "lock" of the password to the picture, with the left and right view can be loaded, of course, the last to remember to set the left and right view mode for always, Otherwise, the default is never not displayed.


-(void) Viewdidload {//textfiled1 This would be textField1, but does not affect Uitextfield *textfiled1=[[uitextfield alloc]init]; At this point the textField1 already exists, but because it is a transparent background, it is invisible, but clicking on that piece of land will find that the cursor is blinking writable//to prove that it is a transparent background instead of a white background, we can set the self.view background to red and see if textField1 is white or transparent    Self.view.backgroundcolor=[uicolor Redcolor];    Textfiled1.frame=cgrectmake (10, 30, 300, 30); Set border style//uitextborderstyleroundedrect-rounded rectangle, background is white, no longer transparent//uitextborderstyleline-rectangle, black border, transparent background//uitextborderstyl    Ebezel-is similar to the above, but is a gray border, the background is transparent textfiled1.borderstyle=uitextborderstyleroundedrect;    Setting the background color overrides the default white background of the rounded rectangle above textfiled1.backgroundcolor=[uicolor Purplecolor];    Set prompt (default) text [email protected] "Please enter your password";    Set ciphertext input, that is, and enter a password similar to the display of small dots textfiled1.securetextentry=yes; Set keyboard style, such as bank withdrawal password only need number, some input mailbox need @ and so on//uikeyboardtypealphabet and Uikeyboardtypedefault similar, is we usually see that, are letters, Then there's a key to toggle the symbol//uikeyboardtypeasciicapable as if it were almost//uikeyboardtypedecimalpad,uikeyboardtypenumberpad on the top, but the former is a number. "Decimal" key//uikeyboardtypeemailaddress-In addition to the letters and the decimal point and @ appear//uikeyboardtypenamephonepad-normal//uikeyboardtypephonepad-telephone keypad, not only the number and the type of * and #//uikeyboardtypenumbe rsandpunctuation-only numbers and punctuation//uikeyboardtypetwitter-in addition to the letters and @ and #, this is the sign of Weibo//uikeyboardtypeurl-in addition to letters, as well as the. com button for easy input//uike    yboardtypewebsearch-The main difference is that the return key becomes Go key//NOTE: If it is the most Xcode6 simulator, the default is not to bring up the soft keyboard, press Cmd+k can be recalled, or in the menu hardware keyboard    Textfiled1.keyboardtype=uikeyboardtypewebsearch; Setting the keyboard appearance//uikeyboardappearancedark and Uikeyboardappearancealert are all turning the keyboard background into translucent gray difference not obvious// Uikeyboardappearancelight looks like Uikeyboardappearancedefault, no difference textfiled1.keyboardappearance=        Uikeyboardappearancealert; Set the pop-up view, Inputview is not the keyboard but this view//set frame, only highly useful, other X and Y and width are not valid, width is the default entire keyboard width Uiimageview *imgview1=[[uiimageview    Alloc]initwithimage:[uiimage imagenamed:@ "[email protected]"];    Imgview1.frame=cgrectmake (60, 60, 300, 300);        Textfiled1.inputview=imgview1;    Set the left view, is the user name and password, and sometimes put a picture of the location UIView *view1=[[uiview Alloc]init]; X and y are not valid, X is 0, and Y is based on heightto auto-adjust. That is, if the height exceeds TextField, the default is TextField high, such as less than textfield height, the upper and lower center display.    The only thing that works is width view1.frame=cgrectmake (10, 500, 50, 10);    View1.backgroundcolor=[uicolor Orangecolor];    Textfiled1.leftview=view1; Most important when: By default it is not displayed as Uitextfieldviewmodenever, we can set always show uitextfieldviewmodealways//    Uitextfieldviewmodeunlessediting-from the beginning, click the box, uh, looks like there's//uitextfieldviewmodewhileediting-. No, click the box appears        Textfiled1.leftviewmode=uitextfieldviewmodealways; Similarly, we can set the right view and of course can also load and picture in Uiimageview *imgview2=[[uiimageview alloc]initwithimage:[uiimage imagenamed:@ "[Email     protected] []];    Imgview2.frame=cgrectmake (10, 500, 50, 10);    Textfiled1.rightview=imgview2;        Textfiled1.rightviewmode=uitextfieldviewmodealways; Set the Clear button, that is, the fork x, the text of the entire input box to delete all the re-entered the X (we first comment out the right view to see the effect)// In fact, we are writing clearbuttonmode is it also hint that this is a uitextfieldviewmode type, so is the same as the above textfiled1.clearbuttonmode=        uitextfieldviewmodewhileediting; Whether to empty the content when editing again, this is rarely used in addition to a specific scene, will let the user crazy//Of course, in order to simulate the re-editing, we need the mouse point to other places and then point back, so create a TEXTFIeld Textfiled1.clearsonbeginediting=no;    This clearsoninsertion seems to click Back to edit again not clear, but as long as the input content will be cleared before the Textfiled1.clearsoninsertion=yes;    Uitextfield *textfield2=[[uitextfield Alloc]init];    Textfield2.frame=cgrectmake (10, 80, 300, 100);    Textfield2.borderstyle=uitextborderstyleroundedrect;        [Self.view Addsubview:textfield2]; We use the textField2 created above to do the following//vertical alignment, the default is centered//uicontrolcontentverticalalignmentcenter center, so top, bottom is home.    Fill looks almost textfield2.contentverticalalignment=uicontrolcontentverticalalignmentfill with top; Of course there are horizontal alignment//There are left and right and fill four kinds, but seemingly did not see what effect, may be invalid for the text, because there is a specific setting for the text textfield2.contenthorizontalalignment=    Uicontrolcontenthorizontalalignmentright;    Set text alignment//the same as we enter textalignment when there are hints nstextalignment type, there are several kinds, not detailed textfield2.textalignment=nstextalignmentcenter;    Set the size of the adjustment text to fit the width (that is, the input is reduced text, it can not be reduced, the backward scrolling), the default is to scroll to the right textfield2.adjustsfontsizetofitwidth=yes;    Set the minimum font size, and the above, that is, less than the size of the time, I will not zoom out, directly to the right to scroll textfield2.minimumfontsize=2; Set Letter Size SampleInput Autocapitalizationtype When prompted is the Uitextautocapitalizationtype type// uitextautocapitalizationtypeallcharacters-all uppercase letters (use the keyboard input words found invalid, need to use soft keyboard input only valid, the following same)//    uitextautocapitalizationtypewords-Word First Capital//uitextautocapitalizationtypesentences-sentence first letter capital        Textfield2.autocapitalizationtype=uitextautocapitalizationtypesentences;    Set return style, have done/go/next/join/google/search/yahoo/emergencycall/send and so on, except the default, other buttons are blue color background        Textfield2.returnkeytype=uireturnkeyemergencycall;        [Self.view addsubview:textfiled1];    [Super Viewdidload]; Do any additional setup after loading the view, typically from a nib.}


"iOS Dev-15" Uitextfield Common Properties: text box style, text style, keyboard style, left and right view style, clear button settings, etc.

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.