how to dismiss keyboard swiftui
extension UIViewController: UITextFieldDelegate{
public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true;
}
}
override func viewDidLoad() {
super.viewDidLoad()
textField.delegate = self
}#if canImport(UIKit)
extension View {
func hideKeyboard() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}
#endif#if canImport(UIKit)
extension View {
func hideKeyboard() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}
#endifstruct 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()
}
}
}
}
Also in Swift:
- Left side of mutating operator isn't mutable: 'self' is immutable
- swift change navigation bar color
- register page
- check when webview finish loading swift
- foreach swift
- Make a VStack fill the width of the screen in SwiftUI
- swipe left to go back iphone swift
- The Swift pod `qr_code_scanner` depends upon `MTBBarcodeScanner`, which does not define modules
- swift textfield trim special characters before database
- swift quit app
- guard let swift
- swipe right to delete swiftui
- add textfield in swiftui
- shadow color swiftui
- settimeout in swift
- swift toggle on change
- ios swift convert int to string
- rtl ios swift
- convert string to base64 swift
- UISearchController keys
- swift get slected row data in tableview cell
- meu eclipse não gera a implementação do mapstruct
- dictionary in swift
- fade anumation swift