Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically switch keyboard from uppercase to lowercase

I would like to turn my user's keyboard from uppercase to lowercase to force typing in lower-case. How can I do this?

like image 419
Albert Renshaw Avatar asked Mar 11 '13 22:03

Albert Renshaw


1 Answers

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.

like image 162
rob mayoff Avatar answered Sep 22 '22 15:09

rob mayoff