I\'ve been having trouble trying to set the UIDatePicker
font and color. Everything else in my app was fairly straightforward to adjust except
Changing the date mode to something else seems to force a re-draw with the newly set text color.
datePicker.setValue(UIColor.whiteColor(), forKeyPath: "textColor")
datePicker.datePickerMode = .CountDownTimer
datePicker.datePickerMode = .DateAndTime //or whatever your original mode was
You can set value using forKeyPath: "textColor". The code:
datePicker.setValue(UIColor.whiteColor(), forKeyPath: "textColor")
where datePicker is your UIDatePicker object, and the first parameter is the color that you want
This worked for me:
setting text color for all date picker subviews
for view in datePicker.subviews {
view.setValue(UIColor.white, forKeyPath: "textColor")
}
In Xcode 11.5, iOS 13, mode is set automatically, by setting the date picker colors in your storyboard as follows:
background: systemBackgroundColor text: labelColor
This results in the following:
I found that I also had to set the interface style in the simulator settings: