Skip to content

Instantly share code, notes, and snippets.

@jimmythai
Created October 7, 2017 10:04
Show Gist options
  • Select an option

  • Save jimmythai/91f5550d0a1eee5efca5337e69202a8b to your computer and use it in GitHub Desktop.

Select an option

Save jimmythai/91f5550d0a1eee5efca5337e69202a8b to your computer and use it in GitHub Desktop.
import UIKit
extension UIViewController {
func hideKeyboardWhenTappedAround() {
let tap = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
view.addGestureRecognizer(tap)
}
@objc func dismissKeyboard() {
view.endEditing(true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment