Change UIDatePicker selected Date text Color for Dark mode (iOS 13)

你离开我真会死。 提交于 2020-01-23 04:59:09

问题


Having trouble to find out a solution for changing the color of text for the selected Date in iOS 13 dark mode.

I know how to change the color of the text of a UIPicker view using code

self.timePicker.setValue(UIColor.black, forKeyPath: "textColor")

OR using User Defined Runtime Attributes. But nothing is working for changing the selected date color for iOS 13 Dark mode. With background white color and black text color, my date picker-view looks like this:

So with changing the text color black, does not change the selected date text color. It changes all the other text color to black; but not the selected one. Selected one stays white, which is default for dark mode.


回答1:


You can set self.window inside AppDelegate.m and override Interface style like so

if (@available(iOS 13, *)) {
    self.window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
}
return YES;

Swift 5.*

if #available(iOS 13.0, *) {
    self.window?.overrideUserInterfaceStyle = .light
}



回答2:


I found something that solves the problem in a way. If I mark 'hightlightsToday' color to false, then the selected text shows with the color you set your code.

self.datePicker.setValue(false, forKey: "highlightsToday")

But if I wanted to highlight my selected date text color with a different color; in that case not sure which key value I have to change. So I am going to leave the question open, incase anyone knows how to change the selected date text color for dark mode.




回答3:


You can resolve this problem via Info.plist file. Add "UIUserInterfaceStyle" key and "Light" value in Info.plist file.

Reference: https://github.com/xgfe/react-native-datepicker/issues/365#issuecomment-532875809



来源:https://stackoverflow.com/questions/58088004/change-uidatepicker-selected-date-text-color-for-dark-mode-ios-13

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!