In SwiftUI, how do I stop a TextField from always beginning with initial caps?

In SwiftUI, I have several TextFields in a Form and they always begin with initial caps when data is entered? How do I prevent this? I want the field to be all lowercase.

Answered by Jim Dovey in 397361022

You should be able to achieve this using the .autocapitalization() modifier:


TextField("Title", text: $myText)
    .autocapitalization(.none)


There's also a .keyboardType() modifier that you may find useful:


TextField("Email", text: $email)
    .autocapitalization(.none)
    .keyboardType(.emailAddress)
Accepted Answer

You should be able to achieve this using the .autocapitalization() modifier:


TextField("Title", text: $myText)
    .autocapitalization(.none)


There's also a .keyboardType() modifier that you may find useful:


TextField("Email", text: $email)
    .autocapitalization(.none)
    .keyboardType(.emailAddress)

I found that .autocapitalization(.none) doesn't work for me in iOS 15. I found .textInputAutocapitalization(.never) does work.

Still broken, over 2 years later.

        TextField("Enter Long URL", text: $longURL)
            .autocorrectionDisabled(true)
            .keyboardType(.URL)
            .textInputAutocapitalization(.none)
            .textFieldStyle(RoundedBorderTextFieldStyle())
            .padding()
In SwiftUI, how do I stop a TextField from always beginning with initial caps?
 
 
Q