Dismiss keyboard on tap outside textfield in Xcode 7.1

  • In viewDidLoad() function of your viewcontroller class copy paste the following code

var tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "DismissKeyboard")
        view.addGestureRecognizer(tap)
  • Add a function
 func DismissKeyboard(){
        view.endEditing(true)
    }

Leave a Reply

Your email address will not be published. Required fields are marked *