我有一个html字符串,我必须在文本视图中显示我已经在NSMutableString中转换它但在该字符串中有多个标题即将到来。我想用蓝色改变标题的颜色。 提前谢谢。
答案 0 :(得分:2)
您可以像这样在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