UI基础控件(二)-------- UITextField

来源:互联网 发布:淘宝商城男装裤子 编辑:程序博客网 时间:2024/04/30 07:50



                               UITextField


一.常用属性

1.文字属性:

  文字属性包括:  text;placeholder(默认使用70%灰色);font;textColor;textAligment。


2.文字大小:

  文字大小包括: adjustsFontSizeToFitWidth;minimumFontSize。


3.编辑行为:

  编辑行为包括:  editing;clearsOnBeginEditing。


4.展现形态:

  展现形态包括:borderStyle(默认 UITextBorderStyleNone,是 UITextBorderStyleRoundedRect 时自定义的 background 无效);background;disabledBackground property(background 未设置时,这个会无效)


5.覆盖视图

  覆盖视图包括:clearButtonMode;leftView(像 clearButton 那样的视图,不过在左边,不要忘了设置 mode);leftViewMode;rightView;rightViewMode。


6.访问代理

  方为代理包括: delegate


7.绘画界面

  以下都不应该直接调用,需要的话可以重写:

  (1)-textRectForBounds:重写来重置文字区域;

  (2)-drawTextRect:改变文字属性,重写时调用 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上面的视图。


二。初始化UITextField

  初始化UITextField控件显示在屏幕上


UITextField * aTextField = [[UITextField alloc] initWithFrame:CGRectMake(100,100,100,50)];aTextField.borderStyle = UITextBorderStyleRoundedRect;[aTextField setText:@"Hello!"];[self.view addsubview: aTextField];[aTextField release];


0 0
原创粉丝点击