I have a custom TextField
and want to be able to use the .keyboardType(.numberPad)
modifier on the CustomTextInputField
rather than having to send it through an initializer. Is this possible to override the modifier or maybe get access to the keyboard type through the environment, is there any other suggestion?
struct CustomTextInputField: View {
@Binding private var text: String
init(text: Binding<String>) {
self._text = text
}
var body: some View {
TextField("Type Text Here", text: $text)
}
}
Yes, we can implement own variant of generic modifier for our custom view. Here is possible solution: