美文网首页
UITextfield

UITextfield

作者: coder_hong | 来源:发表于2016-05-24 22:41 被阅读123次

    头文件

     @interface UITextField : UIControl <UITextInput, NSCoding> 
    

    代理 UITextFieldDelegate

    // 是否允许编辑模式 默认返回YES,进入编辑模式。NO不进入编辑模式
    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; 
    
    // 开始编辑的时候 became first responder
    - (void)textFieldDidBeginEditing:(UITextField *)textField;           
    
    // 是否退出编辑模式
    - (BOOL)textFieldShouldEndEditing:(UITextField *)textField; 
    
    // 
    - (void)textFieldDidEndEditing:(UITextField *)textField;
    
    // 点击清除按钮是否清除 默认返回YES,返回NO不清除
    - (BOOL)textFieldShouldClear:(UITextField *)textField
    
    // 点击键盘上Return按钮时候调用
    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    
    // 当输入任何字符时,代理调用该方法  string为输入的每一个
    Characters
    
    -(BOOL)textField:(UITextField *)field shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    
    

    通知

    // 开始编辑
    UIKIT_EXTERN NSString *const UITextFieldTextDidBeginEditingNotification;
    // 结束编辑
    UIKIT_EXTERN NSString *const UITextFieldTextDidEndEditingNotification;
    // 内容改变 该方法多次调用
    UIKIT_EXTERN NSString *const UITextFieldTextDidChangeNotification;
    

    一些开发中比较重要的属性

    @property (nullable, readwrite, strong) UIView *inputView; 
    
    UntitleDAGA.gif
    typedef NS_ENUM(NSInteger, UITextBorderStyle) {
        UITextBorderStyleNone,
        UITextBorderStyleLine,
        UITextBorderStyleBezel,
        UITextBorderStyleRoundedRect 默认  高度为固定30
    };
    @property(nonatomic)        UITextBorderStyle       borderStyle; 
    
    @property(nullable, nonatomic,copy)   NSAttributedString     *attributedPlaceholder 
    @property(nullable, nonatomic,copy)   NSAttributedString     *attributedText
    @property(nullable, nonatomic,copy)   NSString               *placeholder; 
    @property(null_resettable, nonatomic,strong)   UIColor     *tintColor
    @property(nonatomic)        BOOL                    clearsOnBeginEditing;
    @property(nonatomic)        UITextFieldViewMode  clearButtonMode;
    
    @property(nullable, nonatomic,strong) UIView              *leftView;  
    typedef NS_ENUM(NSInteger, UITextFieldViewMode) {
        UITextFieldViewModeNever,
        UITextFieldViewModeWhileEditing,
        UITextFieldViewModeUnlessEditing,
        UITextFieldViewModeAlways
    };
    @property(nonatomic)        UITextFieldViewMode  leftViewMode;  
    
    @property(nullable, nonatomic,strong) UIView              *rightView; 
    @property(nonatomic)        UITextFieldViewMode  rightViewMode;
    

    相关文章

      网友评论

          本文标题:UITextfield

          本文链接:https://www.haomeiwen.com/subject/kjnzrttx.html