首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用NSAttributedString设置字体

使用NSAttributedString设置字体
EN

Stack Overflow用户
提问于 2016-12-17 18:50:00
回答 0查看 209关注 0票数 1

尝试使用NSAttributedString更改pickerView中的字体:

代码语言:javascript
复制
public func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
    guard let castDict = self.castDict else {
        return nil
    }
    let name = [String](castDict.keys)[row]
    switch component {
    case 0:
        return NSAttributedString(string: name, attributes: [NSForegroundColorAttributeName : AppColors.Rose.color, NSFontAttributeName : UIFont.boldSystemFont(ofSize: 14)])
    case 1:
        guard let character = castDict[name] else {
            return NSAttributedString(string: "Not found character for \(name)", attributes: [NSForegroundColorAttributeName : AppColors.Rose.color, NSFontAttributeName : UIFont.boldSystemFont(ofSize: 14)])
        }
        return NSAttributedString(string: character, attributes: [NSForegroundColorAttributeName : AppColors.LightBlue.color, NSFontAttributeName : UIFont.boldSystemFont(ofSize: 14)])
    default:
        return nil
    }
}

颜色已更改,字体-不是:

我做错了什么?

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41197788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档