Este equipo de trabajo ha pasado mucho tiempo buscando para darle resolución a tu interrogante, te regalamos la respuesta por esto deseamos servirte de gran apoyo.
Solución:
El seguimiento pickerView:attributedTitleForRow:forComponent:
la implementación del método debería ayudarlo a:
func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString?
let attributedString = NSAttributedString(string: "some string", attributes: [NSForegroundColorAttributeName : UIColor.redColor()])
return attributedString
Actualizar
Si quieres usar attributedString
en múltiples if
o switch
declaraciones, las siguientes UIViewController
El ejemplo de subclase lo ayudará a:
import UIKit
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource
@IBOutlet weak var picker: UIPickerView!
let arrayOne = ["One", "Two", "Three", "Four", "Five", "Six"]
let arrayTwo = ["Un", "Deux", "Trois", "Quatre", "Cinq", "Six"]
let arrayThree = [1, 2, 3, 4, 5, 6]
override func viewDidLoad()
super.viewDidLoad()
picker.delegate = self
picker.dataSource = self
func numberOfComponentsInPickerView(_: UIPickerView) -> Int
return 3
func pickerView(_: UIPickerView, numberOfRowsInComponent component: Int) -> Int
switch component
case 0:
return arrayOne.count
case 1:
return arrayTwo.count
case 2:
return arrayThree.count
default:
return NSNotFound
func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString?
var attributedString: NSAttributedString!
switch component
case 0:
attributedString = NSAttributedString(string: arrayOne[row], attributes: [NSForegroundColorAttributeName : UIColor.redColor()])
case 1:
attributedString = NSAttributedString(string: arrayTwo[row], attributes: [NSForegroundColorAttributeName : UIColor.redColor()])
case 2:
attributedString = NSAttributedString(string: toString(arrayThree[row]), attributes: [NSForegroundColorAttributeName : UIColor.redColor()])
default:
attributedString = nil
return attributedString
func pickerView(_: UIPickerView, didSelectRow row: Int, inComponent component: Int)
switch component
case 0:
println(arrayOne[row])
case 1:
println(arrayTwo[row])
case 2:
println(arrayThree[row])
default:
break
Rápido 4.0
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString?
return NSAttributedString(string: pickerData[row], attributes: [NSAttributedStringKey.foregroundColor : UIColor.white])
rápido 3
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString?
let attributedString = NSAttributedString(string: "YOUR STRING", attributes: [NSForegroundColorAttributeName : UIColor.white])
return attributedString
Te mostramos comentarios y puntuaciones
Te invitamos a añadir valor a nuestra información tributando tu veteranía en las observaciones.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)