title: Change selected row label color in picker view swift 1.2
body: <p>I have a created the pickerview with the following code</p>
  
  <pre><code>    @IBOutlet var myPicker: UIPickerView!
  
      var colors: [String] = ["red","green","blue"]
  
      override func viewDidLoad() {
              super.viewDidLoad()     
  
              myPicker = UIPickerView()
              myPicker.dataSource = self
              myPicker.delegate = self
      }
  
      func numberOfComponentsInPickerView(pickerView: UIPickerView) -&gt; Int {
              return 1
          }
  
      func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -&gt; Int {
              return colors.count
          }
  
      func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -&gt; String! {
              return colors[row] as! String
          }
  
      func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
  
          }
  </code></pre>
  
  <p>Now i want to change the label (text) color of the selected row, for example if i scroll down and select blue, the text color should change to orange and the other 2 labels will be black, same follows when i select other rows. i have tried the following code but it doesn't work</p>
  
  <pre><code>func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -&gt; UIView {
          var pickerLabel = UILabel()
          var myTitle:NSAttributedString
          let titleData = colors[row]
          if pickerView.selectedRowInComponent(component) == row {
              myTitle = NSAttributedString(string: titleData, attributes: [NSForegroundColorAttributeName: UIColor.redColor()])
          } else {
              myTitle = NSAttributedString(string: titleData, attributes: [NSForegroundColorAttributeName: UIColor.blueColor()])
          }
  
          //This way you can set text for your label.
          pickerLabel.attributedText = myTitle
  
          return pickerLabel
  
      }
  </code></pre>
  
  <p>I dont know whether i should implement it with didSelectRow or viewForRow method, can someone please help me on this?</p>