注意九宫格系统中文键盘输入特殊字符问题

九宫格中文键盘包含➋➌➍➎➏➐➑➒

解决:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    //获取高亮部分,在
    //UITextRange *selectedRange = [textView markedTextRange];
    //NSString * newText = [textView textInRange:selectedRange];
    NSString *other = @"➋➌➍➎➏➐➑➒";
    if([other rangeOfString:text].location != NSNotFound){
        return  YES;
    }
    //中文字符集
    NSString *regex = @"[\u4e00-\u9fa5A-Za-z0-9]+";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    if ([pred evaluateWithObject:text] || [text isEqualToString:@""]) {
        NSLog(@"输入的是中文字符和回退符号");
        return YES;
    }
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    NSLog(@"输入的不是中文,禁止输入");
    return NO;
}

 

    原文作者:九宫格问题
    原文地址: https://blog.csdn.net/cos_sin_tan/article/details/81698460
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞