Set the maximum character length of a UITextField

前端 未结 30 1655
难免孤独
难免孤独 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 03:07

    You can't do this directly - UITextField has no maxLength attribute, but you can set the UITextField's delegate, then use:

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    

提交回复
热议问题