iOS 14 UIDatePicker as UITextField.inputView

This may be due to the beta, however when you set the UIDatePicker as the input view of a UITextField it no longer displays correctly. (Not visible)

I can still see an associated inputAccessoryView for a toolbar that I have also added to the UITextField, but not the date control.

I cant find it in the view hierarchy either.

Has anyone else come across this yet?

Replies

If you wish to continue using a date picker as a text input field, we would recommend you set the preferredDatePickerStyle to .wheels.

But the preferred recommendation is to adopt the new UI (which defaults to .compact) and make the date picker part of your main UI, or use the new .inline style to enable inline editing if your UI can accommodate.
I have the same issue with my project.
When I have a normal UIPickerView as a inputView for a UITextField it shows up as normally as it would with iOS 13, but when I set a UIDatePicker as an inputView the only thing showing up is the toolbar for the UIDatePicker.

Has the UIDatePicker been changed?
Yes, that is because the default (and only) date picker style available on iOS 13 was .wheels whereas UIKit introduced new (default) styles for iOS 14. If you want to use it as an inputView, you should set your UIDatePicker.preferredDatePickerStyle to .wheels

That being said, the better solution would be to use the new styles and having the date pickers inline in your input form instead of needing to create a separate text field and attaching a date picker as the input view.
Same issue here and no luck setting UIDatePicker.preferredDatePickerStyle to .wheels
Any solution (except substitute the textfields with UIDatePicker)?
I'll try to workaround but some choices are made even for the layout.
To set UIDatePicker.preferredDatePickerStyle to .wheels is necessary indeed but not enough:
In order to show the picker you have to set the frame as well, something like this snippet:
Code Block
if #available(iOS 13.4, *) {
            picker.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 250.0)
            picker.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 250.0)
            picker.preferredDatePickerStyle = .wheels
            picker.preferredDatePickerStyle = .wheels
}


Hope it helps 😉


Using .inline would still work fine when UIDatePicker is set as as UITextField.inputView but major issue that for some reason UIKit hard-limits the keyboard height to some (seems like) calculated value. Say in iPhone 12 mini it's 357.6666pt.

Because UI is laid out to use full width, this pushes picker's header view to something like 6pt and thus render it unusable, since you can't easily tap to change the month/year.