0

How to stop entering value in UITextField if the length is greater then 20 char.

Programmatically.

Janak Nirmal
  • 22,706
  • 18
  • 63
  • 99
applelover
  • 136
  • 1
  • 11

2 Answers2

1

try this

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 
{
    //Set tag for a textfield
    if(textField.tag==10)
    {
        NSUInteger newLength = [textField.text length] + [string length] - range.length;
        return (newLength > 20) ? NO : YES;

    }
}
ipraba
  • 16,485
  • 4
  • 59
  • 58
0

Set the maximum character length of a UITextField

Community
  • 1
  • 1
Umesh K
  • 13,436
  • 25
  • 87
  • 129