如何从UILabel显示来自API的HTML内容(例如图像和视频),期望文本已经完成。有没有一种方法可以从UILabel获取而不使用textview或WebKit所有内容。
我的代码可以处理图像,但是图像很大/被剪切,并且也没有嵌入来自YT或FB的视频
do {
if let htmlMessageData = post?.content.data(using:
String.Encoding.utf16) {
let layoutMessage = try NSMutableAttributedString(data:
htmlMessageData, options:
[NSAttributedString.DocumentReadingOptionKey.documentType:
NSAttributedString.DocumentType.html], documentAttributes: nil)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .justified
layoutMessage.addAttribute(NSAttributedString.Key.paragraphStyle,
value: paragraphStyle, range: NSRange(location: 0, length:
layoutMessage.string.count))
self.contentLabel.attributedText = layoutMessage
}
}
catch {}