// MARK: hide status bar
override var preferredStatusBarStyle : UIStatusBarStyle {
return UIStatusBarStyle.lightContent
}func getAge() -> Int? {
let ageComponents = Calendar.current.dateComponents([.year], from: birthdayPicker.date, to: Date())
return ageComponents.year
}
// Set picker current date
birthdayPicker.maximumDate = Date()// Đóng keyboard sau khi nhập
// #1
nameTextField.delegate = self
workTextField.delegate = self
extension ViewController: UITextFieldDelegate{
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}
// #2
// dismiss keyboard viewdidload
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: Selector.endEditing))
// in helper file
extension Selector {
static let endEditing = #selector(UIView.endEditing(_:))
}
// #3
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
view.endEditing(true)
}// Show Alert
// Helper file
extension UIViewController {
func showAlert(title: String, message: String, buttonTitle: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: buttonTitle, style: .default, handler: nil))
present(alert, animated: true, completion: nil)
}
}
// View
showAlert(title: "Info is miss or invalid", message: "Please fill out correct presonal info", buttonTitle: "OK")