wenn ich Schriftfarbe und Größe in attributedTitleForRow
, Schriftgröße verändert sich nicht ändert, sondern ausgewählte Zeile Farbe geändert:Wie ändert man die Schriftgröße der UIPickerView-Komponente in Swift?
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
var color: UIColor!
var size: UIFont!
switch component {
case 0:
if pickerView.selectedRow(inComponent: 0) == row {
color = UIColor.init(red: 186/255, green: 61/255, blue: 62/255, alpha: 1.0)
size = UIFont(name:"Raleway", size:14)
} else {
color = UIColor.black
}
let attributes: [String: AnyObject] = [
NSForegroundColorAttributeName: color, NSFontAttributeName: size]
return NSAttributedString(string: peopleCount[row], attributes: attributes)
default:
return NSAttributedString()
}
}
und wenn ich Schriftfarbe und Größe in viewForRow
Methode ändern, dann werden alle auch Zeilen Farbwechsel als Schriftgröße:
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
var label = view as! UILabel!
if label == nil {
label = UILabel()
label?.textColor = UIColor.red
}
switch component {
case 0:
label?.text = peopleCount[row]
label?.font = UIFont(name:"Raleway", size:14)
return label!
default:
return label!
}
}
Also, meine Frage ist, wie Schriftgröße für alle Zeilen, aber Farbänderung Zeile nur ausgewählt ändern? wie: