(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 styleuitextborderstyleroundedrect-Rounded rectangle with white background, no longer transparent//uitextborderstyleline-rectangle, black border, transparent background// Uitextborderstylebezel-is similar to the above, but is a gray border, the background is transparent textfiled1.borderstyle=uitextborderstyleroundedrect;//Set background color to overwrite the default white background of the rounded rectangle aboveTextfiled1.backgroundcolor=[uicolor Purplecolor];//Set prompt (default) text[Email protected] "Please enter your password";//Set ciphertext input, which is similar to the display of small dots when entering a passwordTextfiled1.securetextentry=yes;//Set keyboard style, such as bank withdrawal password only need number, some input mailbox need @ and so on //uikeyboardtypealphabet and Uikeyboardtypedefault are similar, that is, we usually see that, are letters, and then there is a button to switch the symbol// Uikeyboardtypeasciicapable seems to be similar to the above//uikeyboardtypedecimalpad,uikeyboardtypenumberpad are numbers, but the former more than a "decimal" button// uikeyboardtypeemailaddress-In addition to the letter and the decimal point and @ appears//uikeyboardtypenamephonepad-normal//uikeyboardtypephonepad-telephone keypad, not only the number and * and # The kind of//uikeyboardtypenumbersandpunctuation-only numbers and punctuation//uikeyboardtypetwitter-in addition to the letters and @ and #, this is the sign of Weibo//uikeyboardtype url-In addition to the letters, there are. com buttons, convenient input//uikeyboardtypewebsearch-The main difference is that the return key becomes the Go keyNote: If the simulator is the most xcode6, the default is not to bring up the soft keyboard, press Cmd+k can be recalled, or in the menu hardware keyboard set textfiled1.keyboardtype= Uikeyboardtypewebsearch;//Set keyboard appearanceUikeyboardappearancedark and Uikeyboardappearancealert are all turning the keyboard background into translucent gray difference is not obvious// Uikeyboardappearancelight looks like Uikeyboardappearancedefault, no difference textfiled1.keyboardappearance= Uikeyboardappearancealert;//Set pop-up view, Inputview pop-up is not the keyboard but this viewWhen the frame is set, only the height is useful, the other X and Y and the width are all invalid, and the width is the default for the entire keyboard width Uiimageview *imgview1=[[uiimageview alloc]initwithimage:[uiimage imagenamed:@ "[email protected]"]; Imgview1.frame=cgrectmake (60, 60, 300, 300); Textfiled1.inputview=imgview1;//Set left view, that is, user name and password, sometimes put a picture of the locationUIView *view1=[[uiview Alloc]init]; X and y are not valid, X is 0, and Y is automatically adjusted to the height. 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 inUiimageview *imgview2=[[uiimageview alloc]initwithimage:[uiimage imagenamed:@ "[email protected]"]; Imgview2.frame=cgrectmake (10, 500, 50, 10); Textfiled1.rightview=imgview2; Textfiled1.rightviewmode=uitextfieldviewmodealways;//Set Clear button, that is, the fork x, click the entire text of the input box to delete all the re-entered the X (we first comment out not to let the right view display, 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 erase content when editing again, this is rarely used except for a specific scenario, which can cause users to freak outOf course, in order to simulate the editing again, 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, default is centerUicontrolcontentverticalalignmentcenter Center, so top, bottom is living in the next. Fill looks almost textfield2.contentverticalalignment=uicontrolcontentverticalalignmentfill with top;//Of course there is horizontal alignmentThere are also 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 alignmentAlso we input textalignment when the hint is the 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 scrolltextfield2.minimumfontsize=2;//Set letter size style, prompt when entering Autocapitalizationtype is Uitextautocapitalizationtype typeuitextautocapitalizationtypeallcharacters-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 etc., except by default, other buttons are blue color backgroundTextfield2.returnkeytype=uireturnkeyemergencycall; [Self.view addsubview:textfiled1]; [Super Viewdidload]; Do any additional setup after loading the view, typically from a nib.}
Iostextfield text Box Basic use