Как отобразить HTML текст в label (How to show html text in UILabel, label) - Swift 5
extension NSAttributedString {
internal convenience init?(html: String) {
guard let data = html.
data(using:
String.
Encoding.utf16,
allowLossyConversion: false)
else {
return nil
}
guard let attributedString =
try?
NSMutableAttributedString(data:
data, options: [
NSAttributedString.DocumentReadingOptionKey.
documentType:
NSAttributedString.DocumentType.
html],
documentAttributes: nil)
else {
return nil
}
self.
init(attributedString:
attributedString)
}
}
// Использование
Yourlabel.attributedText = NSAttributedString(html: "<span> recognized <a href='#/userProfile/NZ==/XQ=='> Punit Kumar </a> for Delivers on time</span>")
Возврат к списку