I would like to turn my user's keyboard from uppercase to lowercase to force typing in lower-case. How can I do this?
Asked
Active
Viewed 5,458 times
5
-
2You could get the UIWindow containing the keyboard and use several very very illegal quartz APIs to simulate a touch down in the general vicinity of the caps key. Or, just let iOS' text controls handle it by setting it's `capitalizationType` as appropriate. Take yer pick. – CodaFi Mar 11 '13 at 22:16
-
@CodaFi the problem is that when I call `textView shouldChangeTextInRange` and use my custom methods to update the textView and then `return NO;` the code is never called to turn off the caps key after the first key is pressed (like capitalizing the first letter of a sentence). So I need to do my custom method, over-ride iOS from adding the text that the user typed and then still return all of the other methods. – Albert Renshaw Mar 11 '13 at 22:39
-
possible duplicate of [First letter in UiTextField lowercase](http://stackoverflow.com/questions/5562910/first-letter-in-uitextfield-lowercase). You're over complicating things, and that's never good. – CodaFi Mar 11 '13 at 22:42
4 Answers
6
Instead of trying to force the keyboard into lower-case, just force the characters to lower-case after the user types them.
You didn't say whether you're using a UITextField
or a UITextView
. Let's suppose you're using a UITextField
.
Declare your view controller to adopt the UITextFieldDelegate
protocol, and set the delegate of the text field to the view controller.
In the view controller, implement this method:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
string = [string lowercaseString];
textField.text = [textField.text stringByReplacingCharactersInRange:range
withString:string];
return NO;
}
If you are using a UITextView
, adopt the UITextViewDelegate
protocol and implement the textView:shouldChangeTextInRange:replacementText:
method.

rob mayoff
- 375,296
- 67
- 796
- 848
2
What you can do is make the string of the text box lowercase after they close the keyboard. For example,
[sender resignFirstResponder];
textField.text = textField.text.lowercaseString;
This makes the text lowercase when they close the keyboard, which does what you want.

Chris Loonam
- 5,735
- 6
- 41
- 63
-
This will be good, except, the way I am changing their text right now forces the caps lock to turn on after every key they press... however the user may want some letter capitalized but as of now wether or not they turn it on or off it will get forced on after each key is pressed. – Albert Renshaw Mar 11 '13 at 22:36