原文链接:http://blog.youkuaiyun.com/tskyfree/article/details/8121915/
该博主总结的很全面,建议查看原文。
下面列出一些方法,以便textField实现常用的效果
UITextField *text = [[UITextField alloc]init];
// 水印
text.placeholder = @"123";
// 右侧的清除叉叉
text.clearButtonMode = UITextFieldViewModeAlways;
// 密码输入
text.secureTextEntry = YES;
// 设置为YES时文本自动缩小以适应窗口。默认是保持原来大小,而让长文滚动
text.adjustsFontSizeToFitWidth = YES;
// return键变成什么键
text.returnKeyType = UIReturnKeyDone;
// 两侧加图片
text.rightView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"name.jpg"]];
text.rightViewMode = UITextFieldViewModeAlways;
// 定制化UITextField对象,重写方法来改变文本字段的现实行为。这些方法会返回一个CGRect结构,指定了文本字段每个部件的边界范围。
// 以下方法可以重写:
// 重置文字区域
[text textRectForBounds:<#(CGRect)#>];
// 改变绘字属性。调用super按默认图形属性绘制,若自己完全重写则不用super
[text drawTextInRect:<#(CGRect)#>];
// 重置占位符区域
[text placeholderRectForBounds:<#(CGRect)#>];
// 改变占位符属性。完全重写不用调用super
[text drawPlaceholderInRect:<#(CGRect)#>];
// 重置边缘区域
[text borderRectForBounds:<#(CGRect)#>];
// 重置编辑区域
[text editingRectForBounds:<#(CGRect)#>];
// 重置clearButton位置
[text clearButtonRectForBounds:<#(CGRect)#>];
// 左右图片位置
[text leftViewRectForBounds:<#(CGRect)#>];
[text rightViewRectForBounds:<#(CGRect)#>];