【发布时间】:2021-02-10 21:45:51
【问题描述】:
我有一个 RTF 文件,通过它我可以将内容作为数据获取(我希望它位于数据中,以便在代码的其他地方使用它)。但是,我想在分配给标签之前为属性字符串添加样式,例如字体。我对如何在下面的代码中应用这些属性感到震惊。请建议我如何做到这一点。这是我的代码
let rtfData = getRTFData()
guard let data = rtfData else {
return
}
if let attributedString = try? NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.rtf], documentAttributes: nil) {
myLabel.attributedText = attributedString
}
在这里,我想将属性添加到属性字符串中,例如
let boldAttributes: [NSAttributedString.Key: Any] = [.font: UIFont.boldSystemFont(ofSize: 14)] 并将这些属性应用于属性文本
【问题讨论】:
-
您是要舍弃原有的属性(字体)还是只将字体加粗并改变其大小?
-
我只是想让字体变粗并改变它的大小