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.
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
return NSAttributedString(string: data[row], attributes: [NSAttributedStringKey.foregroundColor: UIColor.yellow])
}
You could use:
pickerView.setValue(UIColor.yellow, forKeyPath: "textColor")
This will only change the color for the currently selected row.
See also: https://stackoverflow.com/a/9866686/5306470
Updated for Swift 5:
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
return NSAttributedString(string: parksPickerData[row], attributes: [NSAttributedString.Key.foregroundColor: UIColor.white])
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With