如何更改拾取器的颜色?
我不希望更改字体或文本。我的拾取器是填充的,并且完全按照我想要的方式工作,我想要做的是将颜色从黑色更改为我的自定义白色。
发布于 2015-03-25 16:53:13
看一下:http://makeapppie.com/tag/uipickerview-in-swift/
如果你想改变每个元素的标题颜色,你可以实现:
func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let titleData = pickerData[row]
var myTitle = NSAttributedString(string: titleData, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 15.0)!,NSForegroundColorAttributeName:UIColor.whiteColor()])
return myTitle
}Swift 3:
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let titleData = pickerData[row]
let myTitle = NSAttributedString(string: titleData!, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 15.0)!,NSForegroundColorAttributeName:UIColor.white])
return myTitle
}发布于 2019-05-24 16:20:58
适用于日期选择器和普通选择器的*
override func viewDidLoad() {
super.viewDidLoad()
pickerView.setValue(UIColor.blue, forKey: "textColor")
pickerView.setValue(UIColor.black, forKey: "backgroundColor")
}发布于 2018-02-08 14:27:19
Swift 4.0
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let titleData = arrayOfPickerData[row]
let myTitle = NSAttributedString(string: titleData, attributes: [.font:UIFont(name: "Georgia", size: 15.0)!, .foregroundColor:UIColor.white]))
return myTitle
}https://stackoverflow.com/questions/29243564
复制相似问题