慕神8447489
对于Swift 4和Swift 4.2:let htmlString = "" + "
" + "" + "" + "" + "A title
" + "A paragraph
" + " bold text" + ""let htmlData = NSString(string: htmlString).data(using: String.Encoding.unicode.rawValue)let options = [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html]let attributedString = try! NSAttributedString(data: htmlData!, options: options, documentAttributes: nil)textView.attributedText = attributedString对于Swift 3:let htmlString = "" +"" + "" +"" +"" + "A title
" + "A paragraph
" + " bold text" +""let htmlData = NSString(string: htmlString).data(using: String.Encoding.unicode.rawValue)let attributedString = try! NSAttributedString(data: htmlData!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)textView.attributedText = attributedString