任何人都知道如何更改UIDatePicker的行和字体颜色,并避免使用私有Apple api?我找到了这个,但它是非常脏的解决方案:
datePicker.setValue(UIColor.white, forKey: "textColor")
for subview in self.datePicker.subviews {
if subview.frame.height <= 5 {
subview.backgroundColor = UIColor.white
subview.tintColor = UIColor.white
subview.layer.borderColor = UIColor.white.cgColor
subview.layer.borderWidth = 0.5 }
}
if let pickerView = self.datePicker.subviews.first {
for subview in pickerView.subviews {
if subview.frame.height <= 5 {
subview.backgroundColor = UIColor.white
subview.tintColor = UIColor.white
subview.layer.borderColor = UIColor.white.cgColor
subview.layer.borderWidth = 0.5
}
}
self.datePicker.setValue(UIColor.white, forKey: "textColor")
}
要更改DatePickerView
所选矩形的颜色,您可以这样做:
datePicker.subviews[0].subviews[1].layer.borderColor = UIColor.red.cgColor //any color you want
datePicker.subviews[0].subviews[1].layer.borderWidth = 1
datePicker.subviews[0].subviews[2].layer.borderColor = UIColor.red.cgColor //any color you want
datePicker.subviews[0].subviews[2].layer.borderWidth = 1
subviews[1]
是上边界,subviews[2]
是下边界。
你也应该设置borderWidth
使其可见
要在整个DatePicker
中设置文本的颜色,您可以这样做:
datePicker.setValue(UIColor.red, forKey: "textColor")