ios - 在 UILabel 中使用 HTML 标签
问题描述
我有这个 JSON,里面有一些 HTML 标签。
"activities": [
{
"message": "<strong>Henrik</strong> didn't resist a guilty pleasure at <strong>Starbucks</strong>."
},
{
"message": "<strong>Johan</strong> made a roundup."
},
{
"message": "<strong>You</strong> didn't resist a guilty pleasure at <strong>Starbucks</strong>."
},
{
"message": "<strong>Daniel</strong> made a roundup."
},
]
我想使用消息字段显示在 UILabel 上,例如:
cell.descriptionLabel.text = activity.message
我怎样才能做到这一点?
更新,我用过:
let messageString = activity.message
let htmlData = NSString(string: messageString).data(using: String.Encoding.utf8.rawValue)
let options = [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html]
let attributedString = try! NSAttributedString(data: htmlData!,
options: options,
documentAttributes: nil)
cell.descriptionLabel.attributedText = attributedString
但是现在 UILabel 都是 Times New Roman 的,不知道为什么。如何将其更改回默认字体?
解决方案
推荐阅读
- mongodb - 同一个 Kubernetes 集群中的多个 MongoDB 状态集
- xampp - 无法在 MySQL Workbench 中查看表
- javascript - 使用 JavaScript 更改内联 CSS
- c# - 如何在 AuthorizationHandler 中获取 POST 请求参数
- python-3.x - 在主词典中附加词典对象
- html - 创建一个新的空白行元素而不从其上方的行传递值
- python - 如何在 python 中将 datetime.date 对象转换为字符串
- ibm-cloud - IBM Natural Language Understanding - 返回页面标题
- reactjs - 在 reactjs 中添加更多点击时以相反的顺序呈现 JSX 模板
- postgresql - 我想根据 Postgresql 上的数据时间在我的表中添加一列,显示数据中的周数