更改UIPicker的颜色

我怎样才能改变我的select器的颜色?

我不想改变字体或文字。 我的select器是填充和工作正是我想要的,我想要做的是将颜色从黑色更改为我自定义的白色。

看看: 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 } 

如果你想更多的控制自定义select器中的每个元素…

使用UIPickerViewDelegate的 “ viewForRow ”方法。

 func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView { var label: UILabel if let view = view as? UILabel { label = view } else { label = UILabel() } label.textColor = UIColor.blue label.textAlignment = .center label.font = UIFont(name: "My-Custom-Font", size: 20) // or UIFont.boldSystemFont(ofSize: 20) label.adjustsFontSizeToFitWidth = true label.minimumScaleFactor = 0.5 label.text = getTextForPicker(atRow: row) // implemented elsewhere return label } 

很明显,你正在返回的视图可能比UILabel更复杂。