Uppercase characters in UItextfield

前端 未结 17 1316
萌比男神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:19

    You can also use this code.

    -(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range     replacementString:(NSString *)string{
    
        // Uppercase for string which you need 
        textField.text = [textField.text stringByReplacingCharactersInRange:range 
                                     withString:[string uppercaseString]];
    
        // return NO because You have already done it in above code
        return NO;
    }
    

提交回复
热议问题