Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set text color and font for UIDatePicker in iOS8/Swift

I've been having trouble trying to set the UIDatePicker font and color. Everything else in my app was fairly straightforward to adjust except this. Does anybody know how to do this? I'm using Swift for iOS8.

screenshot

like image 622
Fenda Avatar asked Feb 09 '15 18:02

Fenda


2 Answers

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 
like image 138
Dylan Reich Avatar answered Sep 16 '22 16:09

Dylan Reich


you just need to set 2 lines of code in viewdidLoad / viewWillAppear accoding where you using DatePicker.

dobDatePicker.setValue(UIColor.whiteColor(), forKeyPath: "textColor") dobDatePicker.setValue(false, forKey: "highlightsToday") 

See the Result like this:

enter image description here

like image 22
Pravin Kamble Avatar answered Sep 18 '22 16:09

Pravin Kamble