以下是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字体)?
答案 0 :(得分:0)
您可以通过将StrokeWidth
属性设置为负值来加粗字符串而不更改其其他属性。
let attrString = NSAttributedString(string: string as String, attributes: [.strokeWidth: NSNumber(value: -3.0)])