Quote:
Originally Posted by MarkC
Elaborating a bit on the above, here's a piece of code that'll limit the length for you Alex, as well as stopping you entering %, & and ". Define kmaxCharacters in the header...
Code:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (textField.text.length >= kmaxCharacters && range.length == 0)
{
return NO; // return NO to not change text
}else{
if ([string isEqualToString:@"\""] || [string isEqualToString:@"-"] || [string isEqualToString:@"%"] ) {
return NO;
}
return YES;
}
}
|
Thank you for that, I tried to put it in but I don't know which file it goes in and/or if I have to do any linking between the UITextField and the code.