23

Under iOS 14, the date/time pickers in my app are broken. Nothing changed in the project. They're defined in a storyboard and worked fine until I updated a few days ago.

Now they're not spinners; they're large grey boxes with static text in them.

enter image description here

UPDATE: Apple broke existing projects by defaulting date/time pickers' style to "automatic", instead of "wheel" (the only style that previously existed, and for which everyone's existing screen layouts were designed). See Sanzio's answer below.

Oscar
  • 1,603
  • 1
  • 24
  • 36

5 Answers5

33

To add some additional information to Oscar's answer...

UIDatePicker now has three different styles, as per documentation here and here. The date picker's style is accessible by the .preferredDatePickerStyle property which can be set to four different cases:

  1. .automatic - A style indicating that the system picks the concrete style based on the current platform and date picker mode.
  2. .compact - A style indicating that the date picker displays as a label that when tapped displays a calendar-style editor.
  3. .inline - A style indicating that the date pickers displays as an inline, editable field.
  4. .wheels - A style indicating that the date picker displays as a wheel picker.

If you want things to look how they did pre iOS 14, stick with the .wheels style. It is also worth noting that not all styles can accommodate all date and time settings, hence why you can only set a preferred style.

Lastly, this property is only available in iOS 13.4 or newer, so you will have to accomplish version control with something like:

if #available(iOS 13.4, *) {
    yourDatePicker.preferredDatePickerStyle = UIDatePickerStyle.automatic
} else {
    // Fallback on earlier versions
}
Sanzio Angeli
  • 1,441
  • 11
  • 26
  • 1
    Thanks. Unfortunately, the "inline" and "compact" modes are not available in Interface Builder (Xcode 12.0.1). – Oscar Sep 29 '20 at 15:10
  • How to fix the issue if we want to use compact style. I am showing it on UITabBar and its really very bad – Rajender Kumar Apr 10 '21 at 13:38
  • 1
    Can we make changes at one place, so that we don't have to explicitly go to every view which is using date picker and set it's preferred style to wheels? – Anuranjan Bose Apr 29 '21 at 08:22
8
if #available(iOS 13.4, *) {
        datePicker.preferredDatePickerStyle = .wheels
    }
3

It turns out that Apple added a second and very different style of UIDatePicker, and inexplicably made it the default for old projects.

You now have to go into the settings for all of your date/time pickers and change Style from "Automatic" to "Wheels." What "Automatic" is based on and why it doesn't default to the only previously existing style is unknown.

Oscar
  • 1,603
  • 1
  • 24
  • 36
3

If anyone looking for Objective C

if (@available(iOS 13.4, *)) {
        datePicker.preferredDatePickerStyle = UIDatePickerStyleWheels;
    } 
EmmEssEss
  • 31
  • 2
1
in iOS appDelegate.m 

didFinishLaunchingWithOptions . () inside 

if (@available(iOS 14, *)) {
      UIDatePicker *picker = [UIDatePicker appearance];
    picker.preferredDatePickerStyle = UIDatePickerStyleWheels;
}

enter image description here

<DateTimePickerModal
    datePickerContainerStyleIOS={{paddingHorizontal: 40}}
    // display={Platform.OS === "ios" ? "spinner" : "default"}                              
    isVisible={isDatePickerVisible}
    mode={mode}
    maximumDate={new Date()}
    onConfirm={handleConfirm}
    onCancel={hideDatePicker}
    />

detail description

Keshav Gera
  • 8,200
  • 1
  • 56
  • 43