How can I set the maximum amount of characters in a UITextField
on the iPhone SDK when I load up a UIView
?
This should be enough to solve the problem (replace 4 by the limit u want). Just make sure to add delegate in IB.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
return (newString.length<=4);
}