Is it any way to change text color of datepicker in iOS8? I\'ve that it isn\'t possible in iOS7 and prior, something changed in 8th version?
For example I\'ve found
This worked for me:
setting text color for all date picker subviews
for view in datePicker.subviews {
view.setValue(UIColor.white, forKeyPath: "textColor")
}
Possible duplicate: Set text color and font for UIDatePicker in iOS8/Swift
Resolving the issue with black "Today" via highlightsToday set to "false" has a side-effect - it's no longer has "Today" label in the list.
I've found a different solution here which works perfect without any side-effects: Set text color and font for UIDatePicker in iOS8/Swift
datePicker.setValue(UIColor.whiteColor(), forKeyPath: "textColor")
datePicker.datePickerMode = .CountDownTimer
datePicker.datePickerMode = .DateAndTime //or whatever your original mode was
Looks like a dirty hack but that's we have at the moment: changing datePickerMode re-draws it correctly. So just set it to something different from your desired mode and change it back to original.
Still Works, Swift 4 Update
datePicker.setValue(UIColor.white, forKeyPath: "textColor")
This works for me.
datePicker.setValue(UIColor.whiteColor(), forKeyPath: "textColor")
If you don't want the selected text to be black at start you need to set both textColor and highlightsToday :
Found solution at comments of stackoverflow. If you need just to change text color to yours and assign this subclass you your picker. For whiteColor works as magic.
Only minus i've found that color two lines of selected number is still gray.
class ColoredDatePicker: UIDatePicker {
var changed = false
override func addSubview(view: UIView) {
if !changed {
changed = true
self.setValue(UIColor.whiteColor(), forKey: "textColor")
}
super.addSubview(view)
}
}
It's working on iOS 10 only if you set both properties.
datePicker.setValue(UIColor.white, forKeyPath: "textColor")
datePicker.setValue(false, forKeyPath: "highlightsToday")