//
// UITextField.h
// UIKit
//
// Copyright (c) 2005-2014 Apple Inc. All rights reserved.
//
// UITextField所有系统属性方法
//
// 2015年12月7日 周一
NS_ASSUME_NONNULL_BEGIN
#pragma mark - 宏定义
// 边框样式
typedef NS_ENUM(NSInteger, UITextBorderStyle) {
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
};
// 删除按钮出现情景
typedef NS_ENUM(NSInteger, UITextFieldViewMode) {
UITextFieldViewModeNever,
UITextFieldViewModeWhileEditing,
UITextFieldViewModeUnlessEditing,
UITextFieldViewModeAlways
};
#pragma mark - 属性
// 输入框内容
@property(nullable, nonatomic,copy) NSString *text;
// 属性化字符串
@property(nullable, nonatomic,copy) NSAttributedString *attributedText NS_AVAILABLE_IOS(6_0);
// 字体颜色
@property(nullable, nonatomic,strong) UIColor *textColor;
// 字体大小
@property(nullable, nonatomic,strong) UIFont *font;
// 对齐方式
@property(nonatomic) NSTextAlignment textAlignment;
// 边框样式
@property(nonatomic) UITextBorderStyle borderStyle;
// 设置默认属性
@property(nonatomic,copy) NSDictionary<NSString *, id> *defaultTextAttributes NS_AVAILABLE_IOS(7_0);
// 提示文本
@property(nullable, nonatomic,copy) NSString *placeholder;
// 属性化字符串
@property(nullable, nonatomic,copy) NSAttributedString *attributedPlaceholder NS_AVAILABLE_IOS(6_0);
// 再次编辑清空
@property(nonatomic) BOOL clearsOnBeginEditing;
// 自动缩小以适应文本窗口大小.默认是保持原来大小,而让长文本滚动
@property(nonatomic) BOOL adjustsFontSizeToFitWidth;
// 最小字体大小
@property(nonatomic) CGFloat minimumFontSize;
// 代理
@property(nullable, nonatomic,weak) id<UITextFieldDelegate> delegate;
// 背景图片,只有UITextBorderStyleNone的时候改属性有效
@property(nullable, nonatomic,strong) UIImage *background;
// 禁用背景图片
@property(nullable, nonatomic,strong) UIImage *disabledBackground;
// 是否可编辑
@property(nonatomic,readonly,getter=isEditing) BOOL editing;
// 允许编辑文本属性
@property(nonatomic) BOOL allowsEditingTextAttributes NS_AVAILABLE_IOS(6_0);
// 设置属性字典
@property(nullable, nonatomic,copy) NSDictionary<NSString *, id> *typingAttributes NS_AVAILABLE_IOS(6_0);
// 设置删除按钮模式,默认不出现
@property(nonatomic) UITextFieldViewMode clearButtonMode;
// 左边视图
@property(nullable, nonatomic,strong) UIView *leftView;
// 左视图显示模式
@property(nonatomic) UITextFieldViewMode leftViewMode;
// 右视图
@property(nullable, nonatomic,strong) UIView *rightView;
// 右视图显示模式
@property(nonatomic) UITextFieldViewMode rightViewMode;
#pragma mark - 重置区域方法
// 重置边框区域
- (CGRect)borderRectForBounds:(CGRect)bounds;
// 重置文本区域
- (CGRect)textRectForBounds:(CGRect)bounds;
// 重置提示文本区域
- (CGRect)placeholderRectForBounds:(CGRect)bounds;
// 重置编辑文本区域
- (CGRect)editingRectForBounds:(CGRect)bounds;
// 重置清除按钮区域
- (CGRect)clearButtonRectForBounds:(CGRect)bounds;
// 重置左视图区域
- (CGRect)leftViewRectForBounds:(CGRect)bounds;
// 重置右视图区域
- (CGRect)rightViewRectForBounds:(CGRect)bounds;
#pragma mark - 绘文字方法
// 改变绘文字属性
- (void)drawTextInRect:(CGRect)rect;
// 改变绘制提示文本属性
- (void)drawPlaceholderInRect:(CGRect)rect;
#pragma mark - 属性
// 代替标准输入键盘
@property (nullable, readwrite, strong) UIView *inputView;
//编辑时显示在系统键盘或用户自定义的inputView上面的视图
@property (nullable, readwrite, strong) UIView *inputAccessoryView;
// 是否允许再次编辑时在内容中间插入内容
@property(nonatomic) BOOL clearsOnInsertion NS_AVAILABLE_IOS(6_0);
// 指定是否允许文本字段结束编辑,当编辑结束,文本字段会让出first responder
// 要想在用户结束编辑时阻止文本字段消失,可以返回NO
// 这对一些文本字段必须始终保持活跃状态的程序很有用,比如即时消息
- (BOOL)endEditing:(BOOL)force;
#pragma - mark - 代理
@optional
// 点击输入编辑框时调用,返回yes可编辑,返回no不可编辑
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
// 已经开始编辑时调用
- (void)textFieldDidBeginEditing:(UITextField *)textField;
// 将要结束编辑时调用,返回yes可结束编辑,no不能
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField;
// 已经结束编辑调用
- (void)textFieldDidEndEditing:(UITextField *)textField;
// 输入文字时调用
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
// 点击清除按钮时调用,返回yes清除,返回no不可清除
- (BOOL)textFieldShouldClear:(UITextField *)textField;
// 点击return按钮时调用
- (BOOL)textFieldShouldReturn:(UITextField *)textField;
#pragma mark - 通知
// 已经开始编辑通知
UIKIT_EXTERN NSString *const UITextFieldTextDidBeginEditingNotification;
// 已经结束编辑通知
UIKIT_EXTERN NSString *const UITextFieldTextDidEndEditingNotification;
// 已经改变通知
UIKIT_EXTERN NSString *const UITextFieldTextDidChangeNotification;
NS_ASSUME_NONNULL_END