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 :: and in swift1 
Swift :: swift ui enum 
Swift :: swift sleep milliseconds 
Swift :: show back button in navbar swift 
Swift :: uiimageview set image swift 
Swift :: push view controller programmatically swift 5 
Swift :: struct vs enum swift 
Swift :: We use the for loop to iterate over the elements of a dictionary. 
Swift :: custom tab bar swift ios 
Swift :: changing color of background swift 
Swift :: swiftui actionsheet 
Swift :: uiview set inside padding 
Swift :: imageliteral swiftui 
Swift :: defer swift 
Swift :: set font uilabel swift 
Swift :: swiftui foreach enum not all cases 
Swift :: how to set return type swift 
Swift :: swift replace newlines with space 
Swift :: swift subtract dates 
Swift :: Convert JSON to Data 
Swift :: chnage y of fram of view ios swift 
Swift :: swift how to wait in a loop 
Swift :: Swift for Loop inside a while Loop 
Swift :: uiviewcontroller title color 
Swift :: Create a Throwing Function Swift 
Swift :: how to have diffrent size images in a stack view swift 
Swift :: Swift Labeled Statement with break 
Swift :: Memberwise Initializer Swift 
Swift :: image preprocessing in python 
Swift :: swift enumeration 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =