ios - UItextfield 中的大写字符

标签 ios iphone uitextfield uistoryboard

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

我有一个UITextField,我希望键盘只有大写字符。

我使用了一个 Storyboard,我尝试将Cpitalization设置为“All characters”到UITextField properties .

但这并不能解决我的问题...有什么建议吗?

最佳答案

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

self.yourTexField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;

调用委托(delegate)后

//委托(delegate)方法

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

关于ios - UItextfield 中的大写字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21092182/

相关文章:

ios - UICollectionView 中单元格之间的零水平间距不起作用

ios - 使用 NSNumberFormatter 将数字转换为格式

ios - Apple Watch 未配对的 ActivateSession 速度慢

iphone - 将值附加到 NSMutableArray 并保存到 NSUserDefaults

iphone - 如何为 iPhone 应用程序制作文本动画以逐字显示?

android - 通过蓝牙接收消息到 raspberrypi

ios - UIView圆形 mask 动画

iphone - TextField在其他ViewController中的Delegate

ios - HW kbd 无法将(null)设置为键盘焦点 iOS Xamarin.iOS 10.2.1.5

ios - Objective c 键盘不情愿地打开