首页 > 解决方案 > 如何更改 NSAttributedString 字体大小

问题描述

如何更改NSAttributedString已初始化的字体大小

init(data: Data, options: [NSAttributedString.DocumentReadingOptionKey : Any] = [:], documentAttributes: AutoreleasingUnsafeMutablePointer<NSDictionary?>?)

实际上我有包含 html 标签的字符串,我使用Roger Carvalho给出的扩展名。html 标签已正确呈现,但字体与以下给出的常规字体不同FontSizeMetrics

let fontMetrics: FontSizeMetrics = FontSizeMetrics()
let font = UIFont(name: "NotoSans", size: fontMetrics.fontRegular)

标签: iosswift4

解决方案


在 Swift 4 中:

[NSAttributedStringKey.font : UIFont.boldSystemFont(ofSize: 17.0)]


推荐阅读