Changing text color of datepicker
35,484
Solution 1
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)
}
}
Solution 2
Still Works, Swift 4 Update
datePicker.setValue(UIColor.white, forKeyPath: "textColor")
This works for me.
datePicker.setValue(UIColor.whiteColor(), forKeyPath: "textColor")
Solution 3
It's working on iOS 10 only if you set both properties.
datePicker.setValue(UIColor.white, forKeyPath: "textColor")
datePicker.setValue(false, forKeyPath: "highlightsToday")
Solution 4
I've changed text color through inspector (see below)
Solution 5
If you don't want the selected text to be black at start you need to set both textColor and highlightsToday :
![Vasily](https://i.stack.imgur.com/2qoFV.jpg?s=256&g=1)
Author by
Vasily
Updated on February 22, 2020Comments
-
Vasily over 4 years
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 modified picker in Yahoo Weather!
-
Syed Asad Ali almost 9 years[datePicker setValue:[UIColor whiteColor] forKeyPath:@"textColor"]; - in Objective-C
-
Pavan Kotesh over 8 yearsI did this but the current date is still Black color. Any idea what can I do instead?
-
Greg over 8 yearsI had the same issue... it changes all the other dates except the current one.
-
clearlight over 8 yearsThe "only minus"? Anything that doesn't look perfect is a huge minus for discerning apps and customers. It isn't adequately supported by Apple yet.
-
swiftyboi over 8 yearsAnybody find a fix for current date being black?
-
365SplendidSuns over 8 yearsWorking fine for me with. No problems with the current date being black.
-
Vladislav almost 7 yearsSome dates are blacked
-
IvanPavliuk over 4 years'NSUnknownKeyException', reason: '[<_UIAppearance 0x280a0b0f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key textColor.'
-
Michał Ziobro over 4 yearsMaybe using .colorScheme(.light) will be better then inverting colours
-
אורי orihpt over 3 yearsThe second line gives me an error: Thread 1: "-[_UIDatePickerCalendarView setHighlightsToday:]: unrecognized selector sent to instance 0x7b50000c3800"
-
אורי orihpt over 3 yearsNot working with .inline date picker style