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 :: post request in swift 
Swift :: swift do while 
Swift :: swift 5 only the day number from date 
Swift :: swift setinterval 
Swift :: how to change background color of ui button swift 
Swift :: swiftui scrollview 
Swift :: swift go to root view controller 
Swift :: swiftui background color 
Swift :: array swift 
Swift :: swift iterate over a dictionary 
Swift :: swift sort array 
Swift :: add to beginning of array swift 
Swift :: swift edit constraint programmatically 
Swift :: Swift Using insert() 
Swift :: swift pdf thumbnail 
Swift :: swift programmatically set font 
Swift :: how to dismiss a view when touch up inside swift 
Swift :: swift array index of where 
Swift :: Swift for-in Loop 
Swift :: swift subtract dates 
Swift :: swift extension 
Swift :: Swift Create String Instance 
Swift :: Create a Tuple 
Swift :: while loops swift 
Swift :: Swift Equatable Protocol 
Swift :: get character at specifiic location swift 
Swift :: swift view controller background image 
Swift :: struct exsmple 
Swift :: ternary operator in swift 
Swift :: Swift print() with terminator 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =