本文介绍了UItextfield中的大写字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 iOS UIKeyboard 的问题。

我有 UITextField 我只有大写字符的键盘

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

我用 storyboard 我尝试将 Cpitalization 设置为所有字符 UITextField属性

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?

推荐答案

将文本字段类型 autocapitalizationType 设置为 UITextAutocapitalizationTypeAllCharacters 在UITextField上

Set your textfield type autocapitalizationType to UITextAutocapitalizationTypeAllCharacters on the UITextField

self.yourTexField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;

致电委托后

//委托方法

- (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;
}

这篇关于UItextfield中的大写字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 12:57