попробуйте использовать NSAttributedString с опцией NSHTMLTextDocumentType и .utf8 строки кодирования
Swift 3:
extension String {
var htmlAttributedString: NSAttributedString? {
do {
return try NSAttributedString(data: data(using: .utf8)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil)
} catch let error {
print(error.localizedDescription)
}
return nil
}
}
Использование
let htmlStringCode = "<i>Italics </i><b>Bold </b><u>Underline</u><blockquote>block quote<br></blockquote>"
if let htmlText = htmlStringCode.htmlAttributedString {
let attributes = [NSFontAttributeName: UIFont(name: "Open Sans", size: 18.0)!]
let attributedText = NSMutableAttributedString(string: htmlText.string, attributes: attributes)
let htmlString = htmlText.string as NSString
let range = htmlString.range(of: "Italics")
attributedText.addAttribute(NSFontAttributeName, value: UIFont(name: "OpenSans-Italic", size: 18.0)!, range: range)
textView.attributedText = attributedText
}
Я бы попытаться построить 'NSAttributedString' с' опцией NSHTMLTextDocumentType', а затем изменить атрибуты для обеспечения желаемого шрифта на каждой его части. – werediver