It's very simple, you just have to implement one of its delegated methods to return a NSAttributedString
.
For example, the complete implementation of your case would be something like this:
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 2
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return component == 0 ? 31 : 4
}
func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let textColor = UIColor.blueColor()
if component == 0 {
return NSAttributedString(string: "\(row)", attributes: [NSForegroundColorAttributeName : textColor])
} else {
switch row {
case 0:
return NSAttributedString(string: "días", attributes: [NSForegroundColorAttributeName : textColor])
case 1:
return NSAttributedString(string: "semanas", attributes: [NSForegroundColorAttributeName : textColor])
case 2:
return NSAttributedString(string: "meses", attributes: [NSForegroundColorAttributeName : textColor])
case 3:
return NSAttributedString(string: "años", attributes: [NSForegroundColorAttributeName : textColor])
default:
return nil
}
}
}