*初始化UITextField
初始化UITextField控件显示在屏幕上
UITextField *aTextField = [[UITextField alloc] initWithFrame: CGRectMake(100, 100, 100, 40)];
aTextField.borderStyle = UITextBorderStyleRoundedRect;
[aTextField setText: @"文本编辑框"];
[self.view addSubview: aTextField];
1、文本属性
文字属性包括:text; placeholder(默认使用70%灰色);font; textColor: textAligment
2、文字大小
文字大小包括:adjustsFontSizeToFitWidth; minimumFontSize
3、编辑行为
编辑行为包括:editing; clearsOnBeginEditing
4、展现形态
展现形态包括:bordStyle(默认 UITextBorderStyleNone,是 UITextBorderSytleRoundedRect时自定义的background无效);background; disabledBackgound property(background 未设置时,这个会无效)
5、覆盖视图
覆盖视图包括:clearButtonMode; leftView(像clearButton那样的视图,不过在左边,不要忘了设置mode); leftViewMode; rightView; rightViewMode
6、访问代理
访问代理包括:delegate
7、绘画界面
以下都不应该直接调用,需要的话可以重写:
(1)-textRectForBounds:重写来重置文字区域;
(2)-drawTextInRect: 改变文字属性,重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了;
(3)-placehoderRectForBounds: 重写来重置占位符区域;
(4)-drawPlaceholderInRect: 重写改变绘制占位符属性,重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了
(5)-borderRectForBounds: 重写来重置边缘区域;
(6)-editingRectForBounds: 重写来重置编辑区域;
(7)-clearButtonRectForBounds: 重写来重置clearButton位置,改变size可能导致button图片失真;
(8)-leftViewRectForBounds:
(9)-rightViewRectForBounds:
8、代替输入
(1)inputView: 代替标准的系统键盘;
(2)inputAccessoryView: 编辑时显示在系统键盘或用户自定义的inputView上面的视图。
转自《蓝鸥科技iOS开发指南》