我尝试更改选择器视图中标题的字体,但由于某种原因我不能。我可以更改标题的颜色,但字体保持不变?
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let attrTitle = NSAttributedString(string: splitPickerSource[row], attributes: [NSFontAttributeName: UIFont(name: "Avenir-Heavy", size: 17.0)!, NSForegroundColorAttributeName: UIColor.darkGray])
return attrTitle
}
或者我可以实施viewForRow
的委托方法UIPickerView
并从那里添加一个新标签。
尝试打印输出时,maddy 建议的一些调试消息attrTitle
Share Bill With{ NSColor = "UIExtendedSRGBColorSpace 0.117647 0.117647 0.117647 1"; NSFont = "<UICTFont: 0x7fb5f8d14080> font-family: \"Avenir-Heavy\"; font-weight: bold; font-style: normal; font-size: 14.00pt";
任何人都对这种情况有任何想法,为什么我不能修改字体attributedTitleForRow
委托方法?
您犯了一个拼写错误,这就是它不起作用的原因。它应该是
let attrTitle = NSAttributedString(string: splitPickerSource[row], attributes: [NSFontAttributeName: UIFont(name: "Avenir-Heavy", size: 17.0)!, NSForegroundColorAttributeName: UIColor.darkGray])
我在 NSFontAttributeName 应该结束后删除了额外的 size: 14 。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)