UITextField : restrict the maximum allowed value (number) during inputting

前端 未结 5 1160
后悔当初
后悔当初 2021-01-03 14:17

I have a UITextField, I\'d like to restrict the maximum allowed input value in the field to be 1000. That\'s when user is inputting number inside, once the inpu

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-03 14:44

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    {
        if(textField.tag == 3)
        {
            if(textField.text.length >3 && range.length == 0)
            {
                return NO;
            }
            else
            {
                return YES;
            }
        }
    }
    

提交回复
热议问题