UIDatePicker
which is datePickerStyle
, because of this UIDatePicker
creating issue with UITextField inputView
. From iOS 14 and above you need to set the datePickerStyle
in order to make it work.
Add below code when you set the UIDatePicker as inputView.
let datePicker = UIDatePicker()
datePicker.datePickerMode = .time
datePicker.locale = .current
if #available(iOS 14, *) {// Added condition for iOS 14
datePicker.preferredDatePickerStyle = .wheels
datePicker.sizeToFit()
}
txtField.inputView = datePicker
Here if we have iOS 14 and above then we set the datePickerStyle as .wheels
and it solves our problem.
Read our next article: Drop Down List iOS Swift 5
This updated code works