3

I have inserted a UIDatePicker in .compact format, only date, in Swift.

I have done several tests and read many posts but I can not change the color of the text which always remains black.

 pickerInizio.setValue(UIColor.red, forKey: "textColor")
 pickerInizio.tintColor =  UIColor.lightGray

How can I change the DatePicker's text color when using UIDatePickerStyleCompact?

Xcode 13, iOS 14/15

Date Picker

pkamb
  • 33,281
  • 23
  • 160
  • 191
Francesco
  • 77
  • 5
  • textColor works only for `preferredDatePickerStyle = .wheels` – RTXGamer Oct 16 '21 at 12:42
  • 1
    thanks, but in the .compact version it is not possible to change the color of the text? I don't want to change the one on the calendar but the one you see first. Oct16, 2021 – Francesco Oct 16 '21 at 14:22
  • 1
    I dont think apple wants you to modify these components. Their job is to differentiate iOS from other platforms and they want all apps to speak a similar design language. If you want customization you need to build your own components from scratch. But as a workaround/hack you can show a custom button with your own style and use the date picker when the user clicks on that button – Jacob Oct 16 '21 at 15:57
  • 2
    Have you tried `UILabel.appearance(whenContainedInInstancesOf: [UIDatePicker.self]).textColor = .purple`? – Scott Thompson Oct 16 '21 at 21:19
  • 1
    @Scott Thompson thanks your system works but once clicked and you return from the choice of the date it turns black, however it is already a step forward :-) – Francesco Oct 17 '21 at 16:39

0 Answers0