1.代码如下: 最后一位可删除
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField.text.length > 11 && ![string isEqualToString:@""]) {
return NO;
}
}
2.代码如下: 最后一位不可删除
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField.text.length + string.length > n) {
return NO;
}
}