How to close your keyboard by touching a view or return button on the keyboard for UITextField
class SendDropMailVC: UIViewController , UITextFieldDelegate {
@IBOutlet weak var TextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
//to recognize delegate
self.TextField.delegate = self
}
// When you touch anywhere on your view.
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
//when you touch a Return Button on the keyboard.
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
TextField.resignFirstResponder()
return (true)
}
}
Comments
Post a Comment