iOS 一套友好的输入限制方案

2018-09-04  本文已影响11人  豪冷

功能


示例

// 长度限制为 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

仓库


其他

CSDN: https://me.csdn.net/xjh093

上一篇下一篇

猜你喜欢

热点阅读