iPhone Force Textbox Input to Upper Case

前端 未结 11 1636
无人共我
无人共我 2020-12-15 03:01

How do I force characters input into a textbox on the iPhone to upper case?

11条回答
  •  我在风中等你
    2020-12-15 03:33

    To Automatically input uppercase in textfield:

    Case 1: Add UITextDelegate protocol and implement the following method

    -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    {
        textField.text = [textField.text stringByReplacingCharactersInRange:range withString:[string capitalizedString]];
    
        return NO;
    }
    

    Case 2:Set the following parameter in the ViewDidLoad() method in your view controller. Although in this case the user can turnoff the caps button on the keyboard.

    urTextFieldName.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
    

提交回复
热议问题