我在旧版的swift中看到了解释。 必须有一个不同的覆盖方法和编码,让我可以在swift 2.2中更改文本大小... 在此先感谢!!
答案 0 :(得分:4)
要更改字体名称和大小,您可以使用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
}
如果你的字体大小变大,你会想用rowHeightForComponent增加每行的高度:
func pickerView(pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
return 36.0
}