iOS--禁止输入框输入汉字

在项目中有些输入框是不需要输入汉字的,我们可以用程序限制输入的类型

#define kAlphaNum @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

//限制输入汉字
            NSCharacterSet *cs;
            cs = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet];
            NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; //按cs分离出数组,数组按@""分离出字符串
            BOOL canChange = [string isEqualToString:filtered];

你可能感兴趣的:(iOS--禁止输入框输入汉字)