swift text with on keyboard code example
Example 1: How to set back button text in Swift
let backButton = UIBarButtonItem()
backButton.title = "name"
self.navigationController?.navigationBar.topItem?.backBarButtonItem = backButton
Example 2: Close iOS Keyboard by touching anywhere using Swift
extension UIViewController {
func hideKeyboardWhenTappedAround() {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)
}
@objc func dismissKeyboard() {
view.endEditing(true)
}
}
override func viewDidLoad() {
super.viewDidLoad()
self.hideKeyboardWhenTappedAround()
}