I would like to turn off predictive text/autocorrect for a TextField
in SwiftUI. Looks like this was possible in with UITextField
:
Disable UITextField Predictive Text
I checked the Apple documentation for TextField
and googled, but can't find anything about this.
Has anyone found a way to disable the predictive text/autocomplete for a TextField?
Thank you!
This should work:
.disableAutocorrection(true)
Seems like it is now possible using Xcode 11 Beta 5. There is a new modifier to disable the autocorrection on TextField
func disableAutocorrection(_ disable: Bool?) -> some View
https://developer.apple.com/documentation/swiftui/textfield/3367734-disableautocorrection?changes=latest_beta
Xcode 12.3 Swift 5.3
If you need to disable autocorrection on multiple TextField
s, or indeed add other modifiers, then create a custom TextField:
struct TextFieldCustom: View {
let title: String
let text: Binding<String>
init(_ title: String, text: Binding<String>) {
self.title = title
self.text = text
}
var body: some View {
TextField(title, text: text)
.disableAutocorrection(true)
// add any other modifiers that you want
}
}
Example Usage:
Form {
Section(header: Text("Details")) {
TextFieldCustom("Field1", text: $field1)
TextFieldCustom("Feild2", text: $field2)
TextFieldCustom("Field3", text: $field3)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With