想要使用 swift 转换 html 字符串中 h3 标签标题的颜色

Want to convert Colour of h3 tag heading in html string using swift

我有一个 html 字符串,我必须在文本视图中显示它,我已经在 NSMutableString 中转换了它,但在该字符串中有多个标题。我想将标题的颜色更改为蓝色。 提前致谢。

你可以像这样在h3标签中应用颜色

let htmlString: String = "<html><body> <h3><font color=black>Some html string</font></h3> </body></html>"

let temphtmlString : NSString = (htmlString as NSString).stringByReplacingOccurrencesOfString("color=black", withString: "color=blue")


  let attrStr = try! NSAttributedString(
                data: temphtmlString.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
                options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
                documentAttributes: nil)
txtView.attributedText = attrStr