Answers for "dismiss keyboard swiftui"

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

swift dismiss keyboard on return

extension UIViewController: UITextFieldDelegate{
    public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true;
    }
}

override func viewDidLoad() {
    super.viewDidLoad()
    textField.delegate = self
}
Posted by: Guest on March-03-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 "dismiss keyboard swiftui"

Code answers related to "Swift"

Browse Popular Code Answers by Language