Thursday 27 April 2017

How to hide keyboard in swift on pressing return key?

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

    @IBOutlet var myTextField : UITextField

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        self.myTextField.delegate = self;
    }

 func textFieldShouldClear(_ textField: UITextField) -> Bool // called when 'return' key pressed. return false to ignore.
{
        textField.resignFirstResponder()
        return true
    }
}

No comments:

Post a Comment

Remove bottom line in navigation bar

navigationController ?. navigationBar . setBackgroundImage ( UIImage (), for: . any , barMetrics: . default )          navigat...