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?
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
}
You can set capitalization for TextField in the Text Input Traits of Text Field Attributes in XIB(interface Builder).
Swift
yourTextField.autocapitalizationType = .none
set setAutocapitalizationType:UITextAutocapitalizationTypeNone for UITextField.
In Objective-C:
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
In Swift:
textField.autocapitalizationType = .none
For SwiftUI,
TextField("I want entered text to be all lowercase", text:$myText)
.autocapitalization(.none)