Vas*_*ily 27 datepicker swift ios8
是否可以在iOS8中更改datepicker的文本颜色?我认为这在iOS7和之前是不可能的,第8版有什么变化吗?
例如,我在Yahoo Weather中找到了修改过的选择器!

小智 62
仍然有效,Swift 4更新
datePicker.setValue(UIColor.white, forKeyPath: "textColor")
Run Code Online (Sandbox Code Playgroud)
这适合我.
datePicker.setValue(UIColor.whiteColor(), forKeyPath: "textColor")
Run Code Online (Sandbox Code Playgroud)
Vas*_*ily 11
在stackoverflow的注释中找到解决方案.如果您只需要更改文本颜色并将此子类分配给您的选择器.对于whiteColor来说就像魔术一样.
只有减去我发现颜色两行所选数字仍然是灰色的.
class ColoredDatePicker: UIDatePicker {
var changed = false
override func addSubview(view: UIView) {
if !changed {
changed = true
self.setValue(UIColor.whiteColor(), forKey: "textColor")
}
super.addSubview(view)
}
}
Run Code Online (Sandbox Code Playgroud)
小智 11
只有在设置了两个属性时,它才能在iOS 10上运行.
datePicker.setValue(UIColor.white, forKeyPath: "textColor")
datePicker.setValue(false, forKeyPath: "highlightsToday")
Run Code Online (Sandbox Code Playgroud)