簡體   English   中英

如何在Swift 2.2中的Pickerview中更改文本/字體大小?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM