Nish
Nish

Reputation: 193

How to change the selected date text color in swift 3.0

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

Upvotes: 2

Views: 1246

Answers (3)

sandy
sandy

Reputation: 3351

Try this

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

Upvotes: 1

KKRocks
KKRocks

Reputation: 8322

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.

Upvotes: 1

Sumeet Mourya
Sumeet Mourya

Reputation: 434

you can use this:

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

Upvotes: 1

Related Questions