3

I need to change the text color of my .inline style Date Picker. A Google search led me to this post.

This works perfectly on .wheels style, but doesn't work on .inline: ‏

My code:

class ViewController: UIViewController {

    @IBOutlet weak var datePicker: UIDatePicker!

    override func viewDidLoad() {
        super.viewDidLoad()

        datePicker.preferredDatePickerStyle = .inline
    
        self.datePicker.backgroundColor = .blue
    
        datePicker.setValue(UIColor.white, forKeyPath: "textColor")
        datePicker.tintColor = .systemTeal
    }

}

Any help will be appreciated.

אורי orihpt
  • 2,358
  • 2
  • 16
  • 41
  • 1
    I assume no (at least not now). Apple uses collection view inside and set labelColor for each UILabel day explicitly in cell, so it does not react on any external appearance changes. – Asperi Dec 07 '20 at 10:32

2 Answers2

13

If you want to change the font color to white, simply override the date picker's user interface style:

datePicker.overrideUserInterfaceStyle = .dark
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
2

There is no way to change inline styled Date Picker text color in UIKit 14, but here is a workaround you can try:

Override style

I noticed that if you change the theme of the device (between light and dark), the text color of the .inline date picker is changing. So for example if you want a dark-text date picker in dark theme, you can override it:

myDatePicker.overrideUserInterfaceStyle = .light

Heres a image of the result

image

I will keep this post updated if there is any new way to change to any color.

Mr speaker
  • 94
  • 5