我正在将我的HTML字符串呈现在标签上。 我也已经在UIView和WebView上渲染了它。tableview仍然出现毛刺
我应用了此功能,可在标签上呈现html。 这是代码。
func getAttributedString(HTMLString: String) -> NSAttributedString {
let data = Data(HTMLString.utf8)
let attributedString = try? NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)
return attributedString!
}
并按如下所示在cellForRowAt上使用它
discussionListCell.discriptionLabel.attributedText = self.getAttributedString(HTMLString: discussionResponse[indexPath.row].postMsg ?? "")
拥有与图像一起接收的HTML字符串示例。 “他 img src = \“ http:\\ 45.35.4.250 \ DevImageUpload \ 60ac0c0f-7751-4088-9a01-466a51a8a5b7.png \”>“
非常感谢。
答案 0 :(得分:0)
使用Dispatch更新UILabel
DispatchQueue.main.async {
self.discussionListCell.discriptionLabel.attributedText = self.getAttributedString(HTMLString: discussionResponse[indexPath.row].postMsg ?? "")
}
尝试重新加载tableView,如下所示:
DispatchQueue.main.async {
self.tableView.reloadData()
}