我有一个带有UIPickerView
和UIDatePicker
的viewController
,如我的storyboard
截图所示,如下所示。
我试着像解释here那样添加运行时属性。但它只改变了最初突出显示的文本的字体颜色。我想在我的pickerView和datePicker中将文本颜色更改为白色。我不知道如何才能做到这一点。
发布于 2017-05-17 15:04:32
您需要编写此行来更改日期选择器文本颜色,
self.datePicker.setValue(UIColor.white, forKeyPath: "textColor")
它会改变UIDatePicker
的文本颜色
对于PickeView
,您必须将属性字符串设置为
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
return NSAttributedString(string: "Your Text", attributes: [NSForegroundColorAttributeName:UIColor.blue])
}
发布于 2017-05-17 15:32:42
这两行为我赢得了胜利。
NepaliDatePicker.setValue(UIColor.white, forKey: "textColor")
EnglishDatePicker.setValue(UIColor.white, forKey: "textColor")
发布于 2017-05-17 14:59:16
您可以对"UIPickerView“使用"viewForRow”委托方法。
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView {
// Your custom view with custom font here
}
对于UIDatePicker,您不能更改字体,但您可以使用此代码更改textColor。
datePicker.setValue(UIColor.whiteColor(), forKeyPath: "textColor")
datePicker.datePickerMode = .CountDownTimer
datePicker.datePickerMode = .DateAndTime
希望这能有所帮助。
https://stackoverflow.com/questions/44017576
复制相似问题