I've been having some trouble trying to set the UIDatePicker font and color, but colour of label today in datePicker is not changed. Everything else in my app was fairly straightforward to adjust, except this. Does anybody know how to do this?
func updatedatePicker(){
DatePicker.setValue(UIColor.whiteColor(), forKeyPath: "textColor")
DatePicker.setValue(1, forKeyPath: "alpha")
}
In viewDidLoad() :-
DatePicker.addTarget(self, action: #selector(ViewController.updatedatePicker), forControlEvents: UIControlEvents.ValueChanged)
I have face the same issue so i have try something like this, Changing the datePickerMode to something else, it will re-draw with the newly set textColor, also instead of setting textColor in updatedatePicker function set this also in viewDidLoad like this.
Answer updated to latest Swift 4
override func viewDidLoad() {
super.viewDidLoad()
datePicker.setValue(UIColor.white, forKeyPath: "textColor")
datePicker.datePickerMode = .date
datePicker.datePickerMode = .dateAndTime //Set here that mode you want.
datePicker.addTarget(self, action: #selector(selectedDate), for: .valueChanged)
}
If your solution didn't work you can try to add the ext color through inspector like this:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With