I have a created the pickerview with the following code
@IBOutlet var myPicker: UIPickerView!
var colors: [String] = [\"red\",\"green\",\"blue\"]
o
you could do something like the following:
class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
var colors = ["red","green","blue"]
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return colors.count
}
func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let color = (row == pickerView.selectedRowInComponent(component)) ? UIColor.orangeColor() : UIColor.blackColor()
return NSAttributedString(string: colors[row], attributes: [NSForegroundColorAttributeName: color])
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
pickerView.reloadAllComponents()
}
}