Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

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
Comment

how to dismiss keyboard in swift

override func viewDidLoad() {
    super.viewDidLoad()

    //Looks for single or multiple taps. 
    let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")

    //Uncomment the line below if you want the tap not not interfere and cancel other interactions.
    //tap.cancelsTouchesInView = false 

    view.addGestureRecognizer(tap)
}

//Calls this function when the tap is recognized.
@objc func dismissKeyboard() {
    //Causes the view (or one of its embedded text fields) to resign the first responder status.
    view.endEditing(true)
}
Comment

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
}
Comment

PREVIOUS NEXT
Code Example
Swift :: pop view swiftui 
Swift :: Change BackgroundColor of Picker ios swift 
Swift :: date formatter swift 
Swift :: How to control the line spacing in UILabel 
Swift :: swift http request 
Swift :: use timer swift 
Swift :: get current unix timestamp swift ios 
Swift :: fizzbuzz in swift 
Swift :: swift swipe gesture 
Swift :: Save structure in userdefaults ios swift 
Swift :: swipe to delete xcode 
Swift :: swift clear user defaults 
Swift :: alert swiftui 
Swift :: swift 5 only the day number from date 
Swift :: and in swift4 
Swift :: swift animate add subview 
Swift :: swift navigation bar title color 
Swift :: hex color swiftui 
Swift :: set right bar button item swift 
Swift :: swift image 
Swift :: remove key by index dictionary swift 
Swift :: how to make text selectable swiftui 
Swift :: swift string format double 
Swift :: swift how to set warning message 
Swift :: ios get notification payload 
Swift :: swift pass any closer to the function 
Swift :: Create enum of Errors Swift 
Swift :: swift increase int value 
Swift :: How to create a typealias? 
Swift :: func collectionview 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =