I was wondering how can I hide the keyboard using the ‘done’ button when I’m entering in a UITextField.
Thank you,
Unknown.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With