Search code examples
iosswiftuikituidatepickerios14

Changing font color of Date Picker with inline style


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.


Solution

  • 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.