[英]How do i change the text / font size in pickerview in swift 2.2?
我在旧版本的swift中看到了这里的解释。必须有其他的覆盖方法和编码,这将允许我在swift 2.2中更改文本大小。
To change the font name and size you can use viewForRow and an attributed string: 要更改字体名称和大小,可以使用viewForRow和属性字符串:
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: 而且,如果您增大字体大小,则需要使用rowHeightForComponent增加每行的高度:
func pickerView(pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
return 36.0
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.