UITextField小结

文字属性

  •   text  
  •   placeholder   //默认使用70%灰色
  •   font 
  •   textColor 
  •   textAlignment 

文字大小

  •   adjustsFontSizeToFitWidth 
  •   minimumFontSize 

编辑行为

  •   editing     //是否正在编辑(read-only)
  •   clearsOnBeginEditing 

展现形态

  •   borderStyle     //默认UITextBorderStyleNone,是UITextBorderStyleRoundedRect时自定义的background无效
  •   background 
  •   disabledBackground  property    //background未设置时,这个会无效

覆盖视图

  •   clearButtonMode 
  •   leftView   //clearButton那样的视图,不过在左边,不要忘了设置mode
  •   leftViewMode 
  •   rightView   //默认覆盖clearButton
  •   rightViewMode 

访问代理

  •   delegate  property

绘画界面

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

  • – textRectForBounds:  //重写来重置文字区域
  • – drawTextInRect:  //改变绘文字属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了.
  • – placeholderRectForBounds:  //重写来重置占位符区域
  • – drawPlaceholderInRect:  //重写改变绘制占位符属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了.
  • – borderRectForBounds:  //重写来重置边缘区域
  • – editingRectForBounds:  //重写来重置编辑区域
  • – clearButtonRectForBounds:  //重写来重置clearButton位置,改变size可能导致button的图片失真
  • – leftViewRectForBounds:
  • – rightViewRectForBounds:

代替输入

  •   inputView     //代替标准的系统键盘
  •   inputAccessoryView   //编辑时显示在系统键盘或用户自定义的inputView上面的视图

 

 

UITextFieldBorderStyle

typedef enum {
UITextBorderStyleNone,//无框
UITextBorderStyleLine,//线框
UITextBorderStyleBezel,//bezel风格线框
UITextBorderStyleRoundedRect//圆角边框
} UITextBorderStyle;

UITextFieldViewMode

typedef enum {
UITextFieldViewModeNever,
UITextFieldViewModeWhileEditing,
UITextFieldViewModeUnlessEditing,
UITextFieldViewModeAlways
} UITextFieldViewMode; 

Notifications

UITextFieldTextDidBeginEditingNotification

UITextFieldTextDidChangeNotification

UITextFieldTextDidEndEditingNotification

 

委托事件

@protocol UITextFieldDelegate <NSObject>

@optional

 

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;        // 返回NO则不许编辑

- (void)textFieldDidBeginEditing:(UITextField *)textField;           // became first responder

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField;          // 返回YES允许结束并且resign first responder status. 返回NO不许编辑状态结束

- (void)textFieldDidEndEditing:(UITextField *)textField;             // 上面返回YES后执行;上面返回NO时有可能强制执行(e.g. view removed from window)

 

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;   // 返回NO不改变

 

- (BOOL)textFieldShouldClear:(UITextField *)textField;               // clear button事件,返回NO过滤之

- (BOOL)textFieldShouldReturn:(UITextField *)textField;              // 'return' key事件.返回NO过滤之

 

@end


在iPhone应用中通过UITextField填写信息时,经常出现出现自动更正输入信息、首字母大写等情况

尤其是在填写用户名时,这种本想提供便捷的功能反而让人感到特别麻烦

今天查了相关书籍,了解了UITextField的相关属性,其实前面说的这些小功能都是可以定制的。

下面列出UITextField的相关属性(备忘)

属性 简介
autocapitalizationType 定义文本自动大小写样式。
UITextAutocapitalizationTypeNone关闭自动大写。
autocorrectionType 定义文本是否使用iPhone的自动更正功能。
UITextAutocorrectionTypeNO不使用该功能。
enablesReturnKeyAutomatically 当一个输入字段没有文本时,是否金庸Return键。
如果设为YES,那么只有在用户至少输入一个字符后Return键才被激活。
keyboardType 设定用户与输入字段交互时出现的键盘格式。
returnKeyType 设定键盘上Return键上显示的文本。
keyboardAppearance 提供两种键盘呈现样式:默认样式和专用于警告面板的一种样式。
secureTextEntry 当该输入框用于输入密码时,需要将该属性设为YES,即不显示输入内容。




你可能感兴趣的:(UITextField小结)