I want a ‘+’ Sign in the Textfield which cannot be erased. A user should be able to enter values after it and if he presses backspace it should only erase the v
I required the same functionality in my app (user needs to put in country code so I can verify number) and I achieved something similar to what you want using a custom binding:
struct PrefixedTextField: View {
@State private var countryCode = "+"
var body: some View {
let countryCodeCustomBinding =
Binding(
get: { self.countryCode },
set: {
self.countryCode = $0
if self.countryCode.isEmpty { self.countryCode = "+" }
})
return TextField("+91", text: countryCodeCustomBinding).keyboardType(.numberPad)
}
}