Uppercase characters in UItextfield

前端 未结 17 1217
萌比男神i
萌比男神i 2020-12-24 04:34

I have a question about iOS UIKeyboard.

I have a UITextField and I would to have the keyboard with only uppercase characters.<

17条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-24 05:17

    The simplest way would be to implement the editing changed method of the text field and set the textfield's text value to upper case representation of the entered text.

    @property (nonatomic, strong) IBOutlet UITextField *yourTextfield
    
    // add target in code or use interface builder
    [self.yourTextField addTarget:self 
                           action:@selector(uppercaseTextField)
                 forControlEvents:UIControlEventEditingChanged];
    
    - (IBAction)uppercaseTextField:(UITextField*)textField
    {
        textField.text = [textField.text uppercaseString];
    }
    

提交回复
热议问题