Here is a sample code to limit the size of a UITextField:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if ([[textField text] length] + [string length] - range.length > MAX_LENGTH) { return NO; } else { return YES; } }
source share