First letter in UiTextField lowercase

前端 未结 11 1470
旧时难觅i
旧时难觅i 2020-12-24 04:45

How do you make it so that when you start typing on the keyboard after youve clicked on a UITextfield the first letter isn\'t a capital automatically?

相关标签:
11条回答
  • 2020-12-24 05:07

    this code will lowercase all the text field input when you type any thing in your targeted text Field

    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
        }
    
    0 讨论(0)
  • 2020-12-24 05:17

    You can set capitalization for TextField in the Text Input Traits of Text Field Attributes in XIB(interface Builder).

    0 讨论(0)
  • 2020-12-24 05:17

    Swift

    yourTextField.autocapitalizationType = .none
    
    0 讨论(0)
  • 2020-12-24 05:18

    set setAutocapitalizationType:UITextAutocapitalizationTypeNone for UITextField.

    0 讨论(0)
  • 2020-12-24 05:23

    In Objective-C:

    textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    

    In Swift:

    textField.autocapitalizationType = .none
    
    0 讨论(0)
  • 2020-12-24 05:23

    For SwiftUI,

    TextField("I want entered text to be all lowercase", text:$myText)
         .autocapitalization(.none)
    
    0 讨论(0)
提交回复
热议问题