Although I found a couple tutorials for this online however this is as far as I could figure out.
HStack{
TextField("Placeholder", text: $text)
.keyboardType(.numberPad)
Button(action: {
self.hideKeyboard()
}, label: {
Image(systemName: "keyboard.chevron.compact.down")
})
}
#if canImport(UIKit)
extension View {
func hideKeyboard() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}
#endif
Eventhough this works, I would prefer if I could put the button in a toolbar onto of the keypad which I can't figure out how to do.