Basic usage of IOS Uitextfield

Source: Internet
Author: User

Uitextfield *textfield = [[Uitextfield alloc] init];// initialization

textfield.userinteractionenabled = yes;// is available

Textfield.text = @ "Uitextfield"; text

Textfield.delegate = self; Agent

Textfield.frame = CGRectMake (100, 100, 100, 40); size and position

Textfield.textcolor = [uicolor redcolor];// Font Color

Textfield.placeholder = @ "Uitextfield";// prompt character

[TextField Setborderstyle:uitextborderstyleroundedrect]; outer box type Uitextborderstyleroundedrect enumeration type

Textfield.securetextentry = YES; Password Box

Textfield.clearbuttonmode = uitextfieldviewmodewhileediting; edit will show a change X

Uiimageview *imgv=[[uiimageview alloc] initwithimage:[uiimage imagenamed:@ "Right.png"];

TEXTFIELD.RIGHTVIEW=IMGV;

Textfield.rightviewmode = Uitextfieldviewmodealways; add picture to right

Textfield.font = [Uifont systemfontofsize:14.0f];// the size of the text

Textfield.font = [Uifont boldsystemfontofsize:14.0f];// text Bold

Textfield.autocapitalizationtype = Uitextautocapitalizationtypenone; whether the initial letter is automatically capitalized


textfield.clearsonbeginediting = YES; edit it again and empty it .


Textfield.adjustsfontsizetofitwidth = YES; When set to YES , the text automatically shrinks to fit the text window size . The default is to keep the original size , while the long text scrolls

Textfield.minimumfontsize = 20; set the minimum font size for auto-shrink display

Textfield.keyboardtype = Uikeyboardtypenumberpad; Set the keyboard style

Textfield.backgroundcolor = [uicolor graycolor];// background color

Placeholder Color

First Kind

Uicolor *color = [Uicolor Whitecolor];

Textfield.attributedplaceholder = [[Nsattributedstring alloc] initwithstring:@ " username " attributes:@{ Nsforegroundcolorattributename:color}];

The second Kind

[TextField setvalue:[uicolor Whitecolor] forkeypath:@ "_placeholderlabel.textcolor"];//_placeholderlabel.textcolor This can't be changed .

Textfield.returnkeytype =uireturnkeydone; Return key becomes what key

Center text up or down

Textfield.contentverticalalignment = Uicontrolcontentverticalalignmentcenter;

Center text around

Textfield.textalignment = Nstextalignmentcenter;

Textfield.keyboardappearance=uikeyboardappearancedefault; Keyboard Appearance


Uitextfield the distance to the left

CGRect frame = [TextField frame];

Frame.size.width = 15;

UIView *leftview = [[UIView alloc] initwithframe:frame];

Textfield.leftviewmode = Uitextfieldviewmodealways; left margin is 15pix

Textfield.leftview = Leftview;

[TextField becomefirstresponder];// becomes the first responder

[Self.view Addsubview:textfield];


This article is from the "11204872" blog, please be sure to keep this source http://11214872.blog.51cto.com/11204872/1754517

Basic usage of IOS Uitextfield

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.