textField限制输入字符串的字数

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

if (_viewTag == VIEW_TAG) {

if (range.length == 1 && string.length == 0) {

return YES;

}

else if (_modifyTextField.text.length >= 20) {

_modifyTextField.text = [textField.text substringToIndex:20];

return NO;

}

}

return YES;

}

你可能感兴趣的:(textField限制输入字符串的字数)