Answers for "swiftui dismiss keyboard when tap background"

1

how to dismiss keyboard swiftui

#if canImport(UIKit)
extension View {
    func hideKeyboard() {
        UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
    }
}
#endif
Posted by: Guest on October-05-2020
1

how to dismiss keyboard swiftui

struct ContentView: View {
    @State private var tipAmount = ""

    var body: some View {
        VStack {
            TextField("Name: ", text: $tipAmount)
                .textFieldStyle(RoundedBorderTextFieldStyle())
                .keyboardType(.decimalPad)

            Button("Submit") {
                print("Tip: \(self.tipAmount)")
                self.hideKeyboard()
            }
        }
    }
}
Posted by: Guest on November-24-2020

Code answers related to "swiftui dismiss keyboard when tap background"

Code answers related to "Swift"

Browse Popular Code Answers by Language