How to hide the keyboard using ‘done’ button Swift 4
use below code
class ViewController: UIViewController,UITextFieldDelegate
// set delegate in didLoad
override func viewDidLoad() {
super.viewDidLoad()
textField.delegate = self
}
// MARK: - Search Method
func textFieldShouldReturn(_ textField: UITextField) -> Bool
{
textField.resignFirstResponder()
return true
}
Set the delegate on the text field and implement this method. Should do the trick.
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}