new UIDatePicker as inputView

With iOS 13 and earlier we could use UIDatePicker as inputView but what now ?

I tried with ios14 and when the textfield is tapped nothing append.


Code Block swift
var timePicker = UIDatePicker()
self.timePicker.preferredDatePickerStyle = UIDatePickerStyle.wheels
self.timePicker.datePickerMode = UIDatePicker.Mode.time
self.timePicker.minuteInterval = 5
self.startTimeTxtField.inputView = self.timePicker


Is it normal ?




Answered by Frameworks Engineer in 620813022
We are aware of this issue. As a workaround for now you can call sizeToFit on the date picker before assigning it as input view, but after configuring the desired style and mode.

It is also worth noting that the desired design for the new styles is to either use the compact style in place in your lists or other designs and the inline style should be shown by making room for it in your actual design. You should no longer use a date picker as input view if you are using the new styles.
In iOS 14, you should not use the UIDatePicker as the inputView, in fact, you can replace the text field with the UIDatePicker directly. If you use the .inline preferred style, then your uses will just get an inline date picker that has all the input fields configured. If you don't configure the style, the automatic style by default will provide .compact and will display a label that will open the input fields on tap. Check the UIDatePickerStyle API page for more detail or the WWDC20 session Build with iOS pickers, menus and actions to find out more about the new design.
I'm not the original poster but I have the same issue. Andy, I watched that session and read the APIs but nowhere does it say that UIDatePicker is no longer supported for being used as an inputView. There may be designs in which the classic input view is still desired, and it seems like it should still be supported in iOS 14. Is this a bug, anyone from Apple?
I've created a sample project here that shows the bug. The date picker appears to be returning with zero frame, which is perhaps why it's not showing correctly. https://github.com/UberJason/DatePickerWheels
Accepted Answer
We are aware of this issue. As a workaround for now you can call sizeToFit on the date picker before assigning it as input view, but after configuring the desired style and mode.

It is also worth noting that the desired design for the new styles is to either use the compact style in place in your lists or other designs and the inline style should be shown by making room for it in your actual design. You should no longer use a date picker as input view if you are using the new styles.
If you use sizeToFit on the datePicker and sets the preferredDatePickerStyle as wheels it would look like it did in iOS 13.
like so:
Code Block Swift
let datePicker = UIDatePicker()
datePicker.datePickerMode = .time
datePicker.locale = .current
if #available(iOS 14, *) {
datePicker.preferredDatePickerStyle = .wheels
datePicker.sizeToFit()
}
textField.inputView = datePicker


new UIDatePicker as inputView
 
 
Q