Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uppercase characters in UItextfield

I have a question about iOS UIKeyboard.

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

I use a storyboard and I tried to set the Cpitalization as "All characters" to UITextField properties.

But this not solve my problem...any suggestion?

like image 213
Safari Avatar asked Jan 13 '14 13:01

Safari


People also ask

How do you uppercase in Swift?

To convert a String to Uppercase in Swift, use String. uppercased() function. Call uppercased() function on the String. The function returns a new string with the contents of the original string transformed to uppercase alphabets.

What is UITextField?

An object that displays an editable text area in your interface.


1 Answers

Set your textfield type autocapitalizationType to UITextAutocapitalizationTypeAllCharacters on the UITextField

self.yourTexField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters; 

After call delegate

// delegate method

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {     NSRange lowercaseCharRange = [string rangeOfCharacterFromSet:[NSCharacterSet lowercaseLetterCharacterSet]];      if (lowercaseCharRange.location != NSNotFound) {         textField.text = [textField.text stringByReplacingCharactersInRange:range                                                                  withString:[string uppercaseString]];         return NO;     }      return YES; } 

Swift 5.4.2

       self.yourTextField.autocapitalizationType = .allCharacters 
like image 134
codercat Avatar answered Sep 28 '22 01:09

codercat