Reputation: 129
I saw the explanation here in old version of swift.. There must be a different override method and coding that will let me change the text size in swift 2.2 ... Thanks in advance!!
Upvotes: 2
Views: 5173
Reputation: 2908
To change the font name and size you can use viewForRow and an attributed string:
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView {
var label = view as! UILabel!
if label == nil {
label = UILabel()
}
var data = pickerData[row]
let title = NSAttributedString(string: data!, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(36.0, weight: UIFontWeightRegular)])
label.attributedText = title
label.textAlignment = .Center
return label
}
And if you make your font size larger you'll want to increase the height of each row with rowHeightForComponent:
func pickerView(pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
return 36.0
}
Upvotes: 4