UITextField autocapitalizationType UITextAutocapitalizationTypeAllCharacters not working on device

别来无恙 提交于 2019-12-05 05:31:27

Apparently this is a device general settings issue: Settings -> General -> Keyboard -> Auto-Capitalization must be ON to honour the setting of textField.autocapitalizationType to all upper case, else setting the property is ignored, apparently. If I switch it on everything works as expected.

You could try something like this the the textfield delegate:

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (range.length == 0) { // not deleting , but adding a char        
        textField.text = [textField.text stringByAppendingString:[string uppercaseString]];
        return NO;
    }

    return YES;
}

This works only if you try to insert a symbol at the end of the text. Should you want to play with the text in the middle you could play with

range.location

and also you will need to play with the cursor positioning as it will go at the end every time...

I hope this helps someone.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!