[英]How do i change the text / font size in pickerview in swift 2.2?
我在舊版本的swift中看到了這里的解釋。必須有其他的覆蓋方法和編碼,這將允許我在swift 2.2中更改文本大小。
要更改字體名稱和大小,可以使用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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.