【问题标题】:First letter in UiTextField lowercaseUiTextField 中的第一个字母小写
【发布时间】:2011-04-06 07:35:25
【问题描述】:

如何做到这一点,当您在单击 UITextfield 后开始在键盘上输入时,第一个字母不会自动大写?

【问题讨论】:

  • this question 的前两个答案似乎回答了这个问题:这不仅是自动大写,而且还是自动更正问题。关闭自动更正,文本字段的第一个字母不会自动为您设置上限。

标签: iphone objective-c uitextfield


【解决方案1】:

在 Objective-C 中:

textField.autocapitalizationType = UITextAutocapitalizationTypeNone;

在斯威夫特中:

textField.autocapitalizationType = .none

【讨论】:

  • 第一个字母似乎不是这样;就像是在开始一个句子。
  • @DavidDunham 对你这样做是自动更正的。关闭 THAT,文本字段中的第一个字母将保持小写。前两个答案here 显示您需要什么。
【解决方案2】:

您可以在 UITextInputTraits 协议中使用 .autocapitalizationType property 关闭自动大写。

textfield.autocapitalizationType = UITextAutocapitalizationTypeNone;

【讨论】:

    【解决方案3】:

    对于 SwiftUI,

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

    【讨论】:

      【解决方案4】:

      您可以在XIB(interface Builder)的Text Field Attributes的Text Input Traits中设置TextField的大小写。

      【讨论】:

        【解决方案5】:

        为 UITextField 设置 setAutocapitalizationType:UITextAutocapitalizationTypeNone。

        【讨论】:

          【解决方案6】:

          在斯威夫特中:

          textField.autocapitalizationType = UITextAutocapitalizationType.None
          

          【讨论】:

          • 更好,textField.autocapitalizationType = .None
          【解决方案7】:

          在 Swift 中,您可以使用 autocapitalizationType 属性:

          yourTextField.autocapitalizationType = .none
          

          【讨论】:

            【解决方案8】:

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

            textField.autocapitalizationType = .none;
            

            textfield.autocorrectionType = .no;
            

            textField.spellCheckingType = .no
            

            仅设置 .autocapitalizationType = .none;可以工作,但我们最好设置其他两个属性以避免大写自动更正和拼写检查。

            【讨论】:

            • 如何禁用所有大写字母,让用户根本无法输入?
            • 嗨@Outsider,为 UITextField 实现 shouldChangeCharactersIn 委托方法,然后在该方法中用 string.lowercase() 替换一系列字符串并设置 yourTextField.autocapitalizationType = .none
            【解决方案9】:

            试试这个代码:

            textfieldname.autocapitalizationType = UITextAutocapitalizationTypeNone;
            

            【讨论】:

              【解决方案10】:

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

              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
                  }
              

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 2013-11-29
                • 1970-01-01
                • 2018-07-08
                • 2011-12-11
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多