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?
Asked
Active
Viewed 4.2k times
69
-
The first two answers to [this question](https://stackoverflow.com/questions/2474824/iphone-issue-disabling-auto-cap-autocorrect-on-a-uitextfield) seem to answer this: it's not just an auto-capitalization, but also an auto-correction issue. Turn off auto-correct & that first letter of the text field won't be auto-capped for you. – ConfusionTowers Oct 25 '17 at 21:08
10 Answers
177
In Objective-C:
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
In Swift:
textField.autocapitalizationType = .none

ricardopereira
- 11,118
- 5
- 63
- 81

ySgPjx
- 10,165
- 7
- 61
- 78
-
1That doesn’t seem to do it for the very first letter; it’s as if it is starting a sentence. – David Dunham Jul 20 '17 at 19:14
-
2@DavidDunham It's auto-correct that's doing that to you. Turn THAT off, and your first letter in the text field will remain lowercase. The first two answers [here](https://stackoverflow.com/questions/2474824/iphone-issue-disabling-auto-cap-autocorrect-on-a-uitextfield) show what you need. – ConfusionTowers Oct 25 '17 at 21:10
14
You can turn off auto-capitalization with the .autocapitalizationType
property in the UITextInputTraits protocol.
textfield.autocapitalizationType = UITextAutocapitalizationTypeNone;

kennytm
- 510,854
- 105
- 1,084
- 1,005
14
For SwiftUI,
TextField("I want entered text to be all lowercase", text:$myText)
.autocapitalization(.none)

Snips
- 6,575
- 7
- 40
- 64
5
set setAutocapitalizationType:UITextAutocapitalizationTypeNone for UITextField.

saadnib
- 11,145
- 2
- 33
- 54
4
In Swift:
textField.autocapitalizationType = UITextAutocapitalizationType.None

King-Wizard
- 15,628
- 6
- 82
- 76
3
In Swift you can use the autocapitalizationType
property:
yourTextField.autocapitalizationType = .none

Cristik
- 30,989
- 25
- 91
- 127

William Hu
- 15,423
- 11
- 100
- 121
2
To avoid completely there are three properties that we can set
textField.autocapitalizationType = .none;
and
textfield.autocorrectionType = .no;
and
textField.spellCheckingType = .no
Only setting .autocapitalizationType = .none; works but better we set other both the properties to avoid capitalising from autocorrection and spell checking.

nikhilgohil11
- 1,185
- 15
- 26
-
-
Hi @Outsider, implement shouldChangeCharactersIn delegate method for UITextField and then replace a range of string with string.lowercase() in that method and set yourTextField.autocapitalizationType = .none – nikhilgohil11 Jun 19 '19 at 02:08
1
Try this code:
textfieldname.autocapitalizationType = UITextAutocapitalizationTypeNone;

Baby Groot
- 4,637
- 39
- 52
- 71

hardik hadwani
- 556
- 6
- 24
0
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
}

mazenqp
- 345
- 4
- 19