只要 5个字符,markedTextRange
//监听字数变化
- (IBAction)editingChange:(UITextField *)textField
{
NSString *nickName;
switch (textField.tag) {
case 10:
{
if (textField.markedTextRange) {
break;
}
nickName = [textField.textstringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]];
if (nickName.length > 5) {
textField.text = [nickName substringToIndex:5];
}
break;
}
default:
break;
}
}