UIDatePicker issue iOS 14 Swift 5

In iOS 14, Apple introduced a new property of 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

1 comment on “UIDatePicker issue iOS 14 Swift 5

Leave a Reply

Your email address will not be published. Required fields are marked *