UITextField属性一

01、创建TextField

//创建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; 
03text
//输入文本
    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如图:
![这里写图片描述](https://img-blog.csdn.net/20160702190941020)
//不会自动纠正
    myTextField.autocorrectionType = UITextAutocorrectionTypeNo;
DEMO如图:
![这里写图片描述](https://img-blog.csdn.net/20160702191107725)   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值