Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS UIDatePicker - disable KEYPAD entry

I have a UIDatePicker displayed with a WHEEL mode, but when I click on a date, the keyboard comes up, letting me enter a date from KEYPAD. How to disable this ridiculous behavior (why would anyone want that anyway???)

like image 518
ekashking Avatar asked Sep 13 '25 03:09

ekashking


1 Answers

Apple's documentation on this is rather lacking -- I haven't been able to find any reference to that functionality.

However, it is clearly built-in as a convenient method for a user to enter the time with the Keypad.

You can prevent the Keypad from showing like this:

@IBOutlet var datePicker: UIDatePicker!

override func viewDidLoad() {
    super.viewDidLoad()
    
    datePicker.addTarget(self, action: #selector(noKeypad(_:)), for: .editingDidBegin)
}
@IBAction func noKeypad(_ sender: UIDatePicker) {
    sender.resignFirstResponder()
}
like image 180
DonMag Avatar answered Sep 14 '25 19:09

DonMag