关于限制输入字数的实现

if (range.length + range.location > inputView.text.length) {
    
    return NO;
}
NSUInteger newLength = inputView.text.length + string.length  - range.length;
if ([inputView.typeName isEqualToString:@"手机号码"]) {

    return newLength <= 11;
}else if ([inputView.typeName isEqualToString:@"验证码"]) {

    return newLength <= 6;
}else {

    return YES;
}

你可能感兴趣的:(关于限制输入字数的实现)