iOS14: Set text color in UIDatePicker

I am using Xcode Version 12.0 (12A7208) with…
Code Block
picker.preferredDatePickerStyle = .wheels

I have tried:
Code Block
picker.setValue(UIColor.white, forKeyPath: "textColor")
// crash

and …
Code Block
picker.tintColor = UIColor.white
// no change


and …
Code Block
UILabel.appearance(whenContainedInInstancesOf: [UIDatePicker.self]).textColor = UIColor.white
// no change



  • For custom design as per requirment need to change DatePicker text color but by upper code I tried but not changing the color. Its showing default color "white color". I used self.datePicker.preferredDatePickerStyle = .wheels and wants to change text color. Bcz in simulator text color coming black9 but in device white color showing.

Add a Comment

Replies

Apparently you don't need to set the text color UIDatePicker. It automatically changes based on the background. I had been confused because this doesn't seem to work in the simulator. But on the device, it's fine.
In my application user may choose different color schemes. But if user choose color theme with dark background - he can't read black characters. Also if all texts in my application has red color I am need to repaint UIDatePicker texts in the same red color... So it is strange to me that we can't improve design of standard element...
  • After working a lot in ui in ios, i found that ios development sucks. For even a single button you need to work around a lot.

Add a Comment

Maybe you you can set appDelegate.window?.overrideUserInterfaceStyle = .dark the App theme