我尝试更改选择器 View 中标题的字体,但由于某种原因我不能。我可以更改标题的颜色,但字体保持不变?
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
}
或者,我可以为 UIPickerView
实现 viewForRow
委托(delegate)方法,并从那里添加新标签。
尝试打印 attrTitle
时 maddy 建议的一些调试消息
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
委托(delegate)方法?
最佳答案
您输入错误,这就是它不起作用的原因。应该是
let attrTitle = NSAttributedString(string: splitPickerSource[row], attributes: [NSFontAttributeName: UIFont(name: "Avenir-Heavy", size: 17.0)!, NSForegroundColorAttributeName: UIColor.darkGray])
在 NSFontAttributeName 应该结束后,我删除了额外的 size: 14。
关于ios - 在选择器 View 中为行实现的标题没有改变字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40876229/