UITextField属性一
2016-07-02 19:13
357 查看
01、创建TextField
![](http://img.blog.csdn.net/20160702181437657)
![](http://img.blog.csdn.net/20160702182422348)
//创建TextField UITextField *myTextField = [[UITextField alloc] init]; //设置大小 myTextField.frame = CGRectMake(70, 150, 200, 30); //背景颜色 myTextField.backgroundColor = [UIColor magentaColor]; //添加到当前视图显示 [self.view addSubview:myTextField];
02、center //将myTextField置于当前视图的中心 myTextField.center = self.view.center;
03、 text //输入文本 myTextField.text = @"世界, 你好!";
04、placeholder //占位符 myTextField.placeholder = @"请输入信息";
05、textColor //设置字体颜色 myTextField.textColor = [UIColor redColor];
06、textAlignment 文本对齐方式 //文本文字横向居中 myTextField.textAlignment = NSTextAlignmentCenter;
07、enablesReturnKeyAutomatically //默认为No,如果设置为Yes,文本框中没有输入任何字符的话,右下角的返回按钮是disabled的。如果文本框中已经输入字符,则不禁用。 myTextField.enablesReturnKeyAutomatically = YES;
08、borderStyle 设置边框样式,只有设置了才会显示边框样式 //圆角 myTextField.borderStyle = UITextBorderStyleRoundedRect; typedef enum { UITextBorderStyleNone, UITextBorderStyleLine, UITextBorderStyleBezel, UITextBorderStyleRoundedRect } UITextBorderStyle;
09、background 背景图片 //background 背景图片 myTextField.background = [UIImage imageNamed:@"navbar_bg_normal-64"]; 注意:当UITextField的属性borderStyle设置为UITextBorderStyleRoundedRect的时候,background设置是无效的,即: //圆角形式 myTextField.borderStyle = UITextBorderStyleRoundedRect; //background 背景图片 myTextField.background = [UIImage imageNamed:@"navbar_bg_normal-64"];
10、font 字体 //设置输入框内容字体的大小 myTextField.font = [UIFont systemFontOfSize:17]; //设置输入框内容字体的样式和大小 myTextField.font = [UIFont fontWithName:@"Arial" size:20];
11、clearButtonMode 清除文本按钮模式:输入框会有一个×号,用于一次性清除文本内容 //编辑的时候出现 myTextField.clearButtonMode = UITextFieldViewModeWhileEditing; 属性有如下: typedef NS_ENUM(NSInteger, UITextFieldViewMode) { UITextFieldViewModeNever, //重不出现 UITextFieldViewModeWhileEditing, //编辑时出现 UITextFieldViewModeUnlessEditing,//除了编辑的时候都出现 UITextFieldViewModeAlways //总是出现 };
12、secureTextEntry //安全文本模式,一般用于输入密码时需要,每输入一个字符就会变成“.”。 myTextField.secureTextEntry = YES; //默认是NO
13、autocorrectionType键盘自动纠正类型 属性有: typedef NS_ENUM(NSInteger, UITextAutocorrectionType) { UITextAutocorrectionTypeDefault, //默认 UITextAutocorrectionTypeNo, //不自动纠错 UITextAutocorrectionTypeYes, //自动纠错 }; //会自动纠正 myTextField.autocorrectionType = UITextAutocorrectionTypeYES; DEMO如图: ![这里写图片描述](http://img.blog.csdn.net/20160702190941020) //不会自动纠正 myTextField.autocorrectionType = UITextAutocorrectionTypeNo; DEMO如图: ![这里写图片描述](http://img.blog.csdn.net/20160702191107725)
相关文章推荐
- 使用UITextField限制输入金额是正确小数
- iOS开发之自定义UITextField的方法
- iOS App开发中UITextField组件的常用属性小结
- iOS应用开发中使UITextField实现placeholder属性的方法
- 解决iOS7上UITextField限制字数输入导致崩溃问题的方法
- IOS UI学习教程之设置UITextField各种属性
- Swift社交应用文本输入优化汇总
- UITextField常用delegate
- UITextField
- iOS开发1:UITextField控件属性
- iOS UITextField 拾遗(下)
- [Swift]UIKit学习之UITextField的用法
- IOS开发Swift语言UITextField设置靠左的间距
- IOS开发Swift语言键盘遮挡输入框(UITextField)
- iOS UITextField相关
- UIKit,UIView
- iOS关于系统键盘的长度限制
- cocos2d-x 一些有用的函数
- UITextField的使用
- UITextField输入框的字靠右一点显示