Implement the delegate method UITextField shouldChangeCharactersInRange:
set the method to return YES when the string length is less than your maximum value.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if (textField.text.length<3) { return YES; } return NO; }
source share