Limit the size of UITextField

iOS Development,Mac OS X,Objective-C 27 August 2011 0 Comments



// Text field delegates
- (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;
  }
}

https://gist.github.com/1175468