Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UiTextField小写字母中的第一个字母_Iphone_Objective C_Uitextfield - Fatal编程技术网

Iphone UiTextField小写字母中的第一个字母

Iphone UiTextField小写字母中的第一个字母,iphone,objective-c,uitextfield,Iphone,Objective C,Uitextfield,如何使单击UITextfield后开始在键盘上键入时,第一个字母不会自动成为大写?在Objective-C中: textField.autocapitalizationType = UITextAutocapitalizationTypeNone; 迅速: textField.autocapitalizationType = .none textField.autocapitalizationType = UITextAutocapitalizationType.None 可以使用UITR

如何使单击UITextfield后开始在键盘上键入时,第一个字母不会自动成为大写?

在Objective-C中:

textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
迅速:

textField.autocapitalizationType = .none
textField.autocapitalizationType = UITextAutocapitalizationType.None

可以使用UITRAITS协议中的关闭自动大写

textfield.autocapitalizationType = UITextAutocapitalizationTypeNone;

设置setAutocapitalizationType:UITextAutocapitalizationTypeNone for UITextField。

您可以在XIB(界面生成器)中文本字段属性的文本输入特征中设置文本字段的大写。

我想现在是: 请尝试以下代码:

textfieldname.autocapitalizationType = UITextAutocapitalizationTypeNone;
迅速:

textField.autocapitalizationType = .none
textField.autocapitalizationType = UITextAutocapitalizationType.None

当您在目标文本字段中键入任何内容时,此代码将所有文本字段输入的小写字母

func textField(_ textFieldToChange: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
         //just change this charectar username  it's a text field
        if textFieldToChange == username {
            let characterSetNotAllowed = CharacterSet.whitespaces
            if let _ = string.rangeOfCharacter(from:NSCharacterSet.uppercaseLetters) {
                return false
            }
            if let _ = string.rangeOfCharacter(from: characterSetNotAllowed, options: .caseInsensitive) {
                return false
            } else {
                return true
            }
        }
        return true
    }
迅捷的


要完全避免,我们可以设置三个属性

textField.autocapitalizationType = .none;

仅设置.autocapitalizationType=.none;工作但我们最好同时设置其他属性,以避免自动更正和拼写检查带来的麻烦。

对于SwiftUI

TextField("I want entered text to be all lowercase", text:$myText)
     .autocapitalization(.none)

更好的是,
textField.autocapitalizationType=.None
似乎对第一个字母不起作用;这就像是在开始一个句子。@DavidDunham对你这样做是自动更正的。关闭该选项,文本字段中的第一个字母将保持小写。前两个答案说明了你需要什么。前两个答案似乎回答了这个问题:这不仅仅是一个自动大写的问题,也是一个自动更正的问题。关闭“自动更正”&文本字段的第一个字母将不会为您自动加盖。我如何禁用所有大写字母,以便用户根本无法键入它?Hi@Outsier,在UITextField的委托方法中实现shouldChangeCharacters,然后用string.lowercase()替换字符串范围在该方法中,并设置您的TextField.autocapitalizationType=.none
TextField("I want entered text to be all lowercase", text:$myText)
     .autocapitalization(.none)