How to change the UIPickerView text color?

Steve B picture Steve B · Jan 25, 2018 · Viewed 10.9k times · Source

The default UIPickerView color for text is black. There has been some updates to the language in Swift4. I have found my own solution and answered below.

Answer

Steve B picture Steve B · Jan 25, 2018
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
    return NSAttributedString(string: data[row], attributes: [NSAttributedStringKey.foregroundColor: UIColor.yellow])        
}