(1)可以根据需要设置文本框的样式(包括形状、边框颜色、背景等)。
(2)可以根据需要设置文字显示样式(包括输入密码时的密文显示、文字横向居中、纵向居中上下、输入的文字是否首席木大写、文字超过后是否缩小还是向右滚动等)。
(3)可以根据需要设置各种不同的键盘样式(只有数字、只有字母等等)。
(4)还有inputView可以弹出一个视图,用于取代弹出键盘,暂时不知道什么用处,但貌似可以用得地方很多啊。
(5)还有return的样式设置,可以设置为Google也可以设置为Go和Search等更形象的按钮。
(6)还有一个clearsOnBeginEditing是否设置清除按钮也很常用。
(7)还有用得比较多得估计是左右视图,也就是我们常见的用户名和密码的前面还有一个小icon图片表示用户的“小人”和表示密码的“锁”的图片,用左右视图可以加载进来,当然最后要记得设置左右视图模式为Always,不然默认是Never不显示的。
- - (void)viewDidLoad {
-
- UITextField *textFiled1=[[UITextField alloc]init];
-
-
- textFiled1.frame=CGRectMake(10, 30, 300, 30);
-
-
-
-
- textFiled1.borderStyle=UITextBorderStyleRoundedRect;
-
- textFiled1.backgroundColor=[UIColor purpleColor];
-
- textFiled1.placeholder=@"请输入您的密码";
-
- textFiled1.secureTextEntry=YES;
-
-
-
-
-
-
-
-
-
-
-
-
- textFiled1.keyboardType=UIKeyboardTypeWebSearch;
-
-
-
- textFiled1.keyboardAppearance=UIKeyboardAppearanceAlert;
-
-
-
- UIImageView *imgView1=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"logo-60@3x.png"]];
- imgView1.frame=CGRectMake(60, 60, 300, 300);
- textFiled1.inputView=imgView1;
-
-
- UIView *view1=[[UIView alloc]init];
-
- view1.frame=CGRectMake(10, 500, 50, 10);
- view1.backgroundColor=[UIColor orangeColor];
- textFiled1.leftView=view1;
-
-
-
- textFiled1.leftViewMode=UITextFieldViewModeAlways;
-
-
- UIImageView *imgView2=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"logo-60@3x.png"]];
- imgView2.frame=CGRectMake(10, 500, 50, 10);
- textFiled1.rightView=imgView2;
- textFiled1.rightViewMode=UITextFieldViewModeAlways;
-
-
-
- textFiled1.clearButtonMode=UITextFieldViewModeWhileEditing;
-
-
-
- textFiled1.clearsOnBeginEditing=NO;
-
- textFiled1.clearsOnInsertion=YES;
- UITextField *textField2=[[UITextField alloc]init];
- textField2.frame=CGRectMake(10, 80, 300, 100);
- textField2.borderStyle=UITextBorderStyleRoundedRect;
- [self.view addSubview:textField2];
-
-
-
-
- textField2.contentVerticalAlignment=UIControlContentVerticalAlignmentFill;
-
-
- textField2.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
-
-
- textField2.textAlignment=NSTextAlignmentCenter;
-
- textField2.adjustsFontSizeToFitWidth=YES;
-
- textField2.minimumFontSize=2;
-
-
-
-
- textField2.autocapitalizationType=UITextAutocapitalizationTypeSentences;
-
-
- textField2.returnKeyType=UIReturnKeyEmergencyCall;
-
- [self.view addSubview:textFiled1];
-
- [super viewDidLoad];
-
- }
[转]UITextField常用属性归纳:文本框样式、文字样式、键盘样式、左右视图样式、清除按钮设置等
原文:http://www.cnblogs.com/ianhao/p/4442794.html