I have three UITextField's which I want to limit in length. The first and second text field to 24 characters and the third text field to 32 characters.
I found this solution for limiting the characters in a UITextField which works very fine:
#define MAXLENGTH 10
- (BOOL)textField:(UITextField *) textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSUInteger oldLength = [textField.text length];
NSUInteger replacementLength = [string length];
NSUInteger rangeLength = range.length;
NSUInteger newLength = oldLength - rangeLength + replacementLength;
BOOL returnKey = [string rangeOfString: @"\n"].location != NSNotFound;
return newLength <= MAXLENGTH || returnKey;
}
But this solution suggests, that every text-field is limited to same length (i.e. 10 characters as defined at the top of the code snippet). I was wondering if there is a chance to define some kind of property for each of my text-fields separately in the Interface-Builder of XCode which allows me to read out in the code -- so that I could replace "MAXLENGTH" with something like "[textField valueForKey:@"maxLength"]" where "maxLength" would be defined visually in the XCode Interface-Builder...
Any ideas?