2016.9.1
UITextField本身提供了相应的事件监听
[textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- (void)textFieldDidChange:(UITextField *)textField{ if (textField == self.titleField) { if (textField.text.length > 20) {
textField.text = [textField.text substringToIndex:20];
}
}}