更改UIPicker颜色

use*_*001 6 colors uipickerview ios swift

如何更改选择器的颜色?

我不想改变字体或文字.我的选择器是填充和完全按我想要的方式工作,我想要做的是将颜色从黑色更改为我的自定义白色.

You*_*jen 19

请查看: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
}
Run Code Online (Sandbox Code Playgroud)

斯威夫特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
}
Run Code Online (Sandbox Code Playgroud)


Sai*_*ddy 5

*对于日期选择器和普通选择器

   override func viewDidLoad() {
   super.viewDidLoad()
   pickerView.setValue(UIColor.blue, forKey: "textColor")
   pickerView.setValue(UIColor.black, forKey: "backgroundColor")
 }
Run Code Online (Sandbox Code Playgroud)