NSAttributedString:如何将BOLD添加到自定义(例如,Palatino)字体?

时间:2015-10-18 19:53:23

标签: swift fonts nsattributedstring

以下是Palatino字体的NSAttributedString类的一些自定义扩展函数:

extension NSAttributedString {
    class func blueAttributeStringOf(string:NSString) -> NSAttributedString {
        let dict = [NSFontAttributeName: UIFont(name: "Palatino", size: 14.0)!,NSForegroundColorAttributeName:blissBlue]
        let attrString = NSAttributedString(string:string as String, attributes: dict)
        return attrString
    }

    class func standardAttributeStringOf(string:String) -> NSAttributedString {
        let dict = [NSFontAttributeName: UIFont(name: "Palatino", size: 14.0)!]
        let attrString = NSAttributedString(string:string as String, attributes: dict)
        return attrString
    }
}

我找不到NSAttributedString类的粗体属性。如何将粗体属性添加到任何特定字体(例如,Palatino字体)?

1 个答案:

答案 0 :(得分:0)

您可以通过将StrokeWidth属性设置为值来加粗字符串而不更改其其他属性。

let attrString = NSAttributedString(string: string as String, attributes: [.strokeWidth: NSNumber(value: -3.0)])