功能
-
为
UITextField
和UITextView
添加输入限制 -
限制类型:
1.长度限制
2.类型限制
3.自定义字符限制
示例
// 长度限制为 9
_textView.jh_inputLimit.length = 9;
// 类型限制为:字母、数字、自定义字符
_textView.jh_inputLimit.type = JHInputLimitType_Alphabet | JHInputLimitType_Digital | JHInputLimitType_MyCharacters;
// 指定自定义字符为: ! 和 ,
_textView.jh_inputLimit.myCharacter = [NSSet setWithArray:@[@"!",@","]];
API
typedef NS_OPTIONS(NSUInteger, JHInputLimitType) {
JHInputLimitType_None = 0, /* 任何字符*/
JHInputLimitType_Alphabet = 1 << 0, /* 字母*/
JHInputLimitType_Digital = 1 << 1, /* 数字*/
JHInputLimitType_Alphabet_Upper = 1 << 2, /* 大写字母*/
JHInputLimitType_Alphabet_Lower = 1 << 3, /* 小写字母*/
JHInputLimitType_Chinese = 1 << 4, /* 中文,基本汉字,Unicode:0x4E00-0x9FA5 */
JHInputLimitType_MyCharacters = 1 << 5, /* 自定义的字符串,custom characters*/
};
@interface JHInputLimit : NSObject
/** Default is 0, it means no limit of max length.*/
@property (nonatomic, assign) NSUInteger length;
/** Limit type of input.*/
@property (nonatomic, assign) JHInputLimitType type;
/** Customt characters, the 'type' should contain 'JHInputLimitType_MyCharacters'.*/
@property (nonatomic, strong) NSSet *myCharacter;
@end
网友评论