我正在尝试更改UIPickerView的字体。
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView {
let label = UILabel()
label.font = UIFont(name:"SynchroLetPlain", size:20)
//label.font = UIFont.systemFont(ofSize: 17) //Even I use systemFont, it doesn't show nothing
return label
}
可以编译,但不显示任何文本。
哪里不同?我检查了SynchroLetPlain是否包含在项目中。
最佳答案
试试这个
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
var label: UILabel
if let view = view as? UILabel {
label = view
} else {
label = UILabel()
}
label.font = UIFont(name:"SynchroLetPlain", size:20)
// where data is an Array of String
label.text = "" // set data here
return label
}
另外:
func printFonts()
{
for fontFamilyName in UIFont.familyNames {
print("-- \(fontFamilyName) --", terminator: "")
for fontName in UIFont.fontNames(forFamilyName: fontFamilyName ) {
print(fontName)
}
print(" ", terminator: "")
}
}
调用此函数,该函数为您提供设置字体所必须使用的字体的确切名称。
关于ios - 更改UIPickerView的标签,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44157801/