0

I'm trying to change text font and color of picker view. But when i do that i get an error, please help.

func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
    let attributedString = NSAttributedString(string: "some string", attributes: [NSForegroundColorAttributeName : UIColor.red])
    return attributedString
}

ErrorImage

rmaddy
  • 314,917
  • 42
  • 532
  • 579
ahmed
  • 115
  • 9

2 Answers2

0

i did something like that by providing a view like this

    func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
          let pickerLabel = UILabel()
          pickerLabel.textColor = UIColor.black
          pickerLabel.text = "\(dataSource[row])"

          pickerLabel.font = UIFont(name: "OpenSans-Light", size: 70)
          pickerLabel.textAlignment = NSTextAlignment.center
          return pickerLabel
       }

func numberOfComponents(in pickerView: UIPickerView) -> Int {
      return 1
   }

   func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
      return dataSource.count
   }
zombie
  • 5,069
  • 3
  • 25
  • 54
0

You have to implement the methods that the UIPickerViewDataSource wants you to implement. These include:

func numberOfComponents(in pickerView: UIPickerView) -> Int

and

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int

ex:

func numberOfComponents(in pickerView: UIPickerView) -> Int {
    return 1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    return 10
}
Aaron
  • 6,466
  • 7
  • 37
  • 75