2

This is my code of creating DataPicker programatically. I need to change the selected date text color to pink. But it is black by default. i used the below code but not working. I referred few links but not working. Thanks in advance How to change the datepicker current date text color?

self.datePicker = UIDatePicker(frame:CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 216))
self.datePicker.backgroundColor = UIColor.white
self.datePicker.datePickerMode = UIDatePickerMode.dateAndTime
textField.inputView = self.datePicker
Nish
  • 183
  • 4
  • 13
  • Check this: https://stackoverflow.com/questions/25900632/how-do-i-change-the-text-color-of-uipickerview-with-multiple-components-in-swift – BadCodeDeveloper Jun 29 '17 at 06:20

3 Answers3

1

you can use this:

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

Sumeet Mourya
  • 434
  • 1
  • 7
  • 23
1

The appearance of UIDatePicker is not customizable. You should integrate date pickers in your layout using Auto Layout. Although date pickers can be resized, they should be used at their intrinsic content size.Apple Doc

If you want to customised datepicker. you can use UIPickerView.

KKRocks
  • 8,222
  • 1
  • 18
  • 84
1

Try this

datePicker.setValue(UIColor.whiteColor(), forKeyPath: "textColor")

sandy
  • 3,311
  • 4
  • 36
  • 47
  • FYI - this is an undocumented, private API that could stop working or even cause a crash in any future iOS update. – rmaddy Jun 29 '17 at 07:23
  • Why was this chosen as the accepted answer when it simply replicates the code already being used in the question? If this is the correct answer, why was the question even asked? – rmaddy Jun 29 '17 at 07:24