UIPickerView text color not changing until touching the picker.

Has anyone else run into this problem?


The picker view is working but the text does not change until after I have touched to picker view.

Very simple code set up;



PickerView.delegate = self

PickerView.dataSource = self

PickerView.setValue(UIColor.red, forKey: "textColor")

PickerView.backgroundColor = UIColor.black



Everything works fine, but the deafult text is balck so the "row titles" do not display on launch, but rather change to the selected 'red' after engaging the picker view.

A very odd problem.

I don't consider this the solution if you wanted to change infromation in the UIPickerView but this does work.


public func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {

let titleData = MyArrayOfData[row]

let myTitle = NSAttributedString(string: titleData, attributes: [NSAttributedStringKey.font:UIFont(name: "Helvetica", size: 17.0)!,NSAttributedStringKey.foregroundColor:UIColor.white])

return myTitle

}

This is the correct solution because it does not rely on private APIs (unlike the first code snippet).


I don't consider this the solution if you wanted to change infromation in the UIPickerView


What do you mean by "change information"? You can easily change the text or color by calling UIPickerView.reloadComponent(_:) or UIPickerView.reloadAllComponents().

UIPickerView text color not changing until touching the picker.
 
 
Q