UITextField输入框部分常用属性

2018-11-02  本文已影响0人  我骑着蜗牛走天下

//设置输入框占位字符的颜色

_Txt.attributedPlaceholder = [[NSAttributedString alloc] initWithString:_Txt.placeholder attributes:@{
NSForegroundColorAttributeName: kColorWithHexString(0xA6A5AB)}];

设置text右侧清除按钮

self.textField.clearButtonMode = UITextFieldViewModeAlways;

设置text的边框样式(圆角)

text.borderStyle = UITextBorderStyleRoundedRect;

设置text左侧图片

textFiled.leftViewMode=UITextFieldViewModeAlways;
textFiled.leftView=[[UIImageViewalloc]initWithImage:[UIImageimageNamed:image]];

设置text默认显示文字(但是不作为文本内容的一部分)

text.placeholder = @"请输入用户名";

设置text文字

text.text = @"什么";

设置文本颜色

text.textColor = [UIColor blackColor];

设置文本的对齐方式

text.textAlignment = NSTextAlignmentCenter;

设置文字字体

text.font = [UIFont systemFontOfSize:18];

设置输入框是否可编辑

text.enabled = YES;

设置当开始编辑时,是否清除框中内容

text.clearsOnBeginEditing = YES;

设置密码格式(输入框中内容是否以点的形式显示)

text.secureTextEntry = YES;

设置弹出键盘的样式(数字键盘)

text.keyboardType = UIKeyboardTypeNumberPad;

键盘右下角显示样式

text.returnKeyType = UIReturnKeyGo;
上一篇下一篇

猜你喜欢

热点阅读