Set the maximum character length of a UITextField

前端 未结 30 1644
难免孤独
难免孤独 2020-11-22 02:27

How can I set the maximum amount of characters in a UITextField on the iPhone SDK when I load up a UIView?

30条回答
  •  抹茶落季
    2020-11-22 02:53

    now how many characters u want just give values

     - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range   replacementString:(NSString *)string {
         NSUInteger newLength = [textField.text length] + [string length] - range.length;
         return (newLength > 25) ? NO : YES;
      }
    

提交回复
热议问题