Setting the text colour of a UIDatePicker in Swift

◇◆丶佛笑我妖孽 提交于 2019-12-12 04:07:49

问题


I need to set the text colour of my Date Picker to white, i have had a look around and have tried to set it by creating a keyPath called "textColor" of type "Color" and then setting the colour, this works fine but the current date stays black. Does anyone have a solution for this?


回答1:


You can use

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

Or try

another way to customise Picker

DatePicker.backgroundColor = UIColor.blueColor()
DatePicker.setValue(UIColor.greenColor(), forKeyPath: "textColor")
DatePicker.setValue(0.8, forKeyPath: "alpha")



回答2:


I think you are searching for this:

datePicker.setValue(UIColor.whiteColor(), forKey: "textColor")
datePicker.performSelector("setHighlightsToday:", withObject:UIColor.whiteColor())


来源:https://stackoverflow.com/questions/35847463/setting-the-text-colour-of-a-uidatepicker-in-swift

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