【发布时间】:2016-05-23 06:07:54
【问题描述】:
我有一个 html 字符串,我必须在文本视图中显示它,我已将它转换为 NSMutableString,但在该字符串中会有多个标题。我想将标题的颜色更改为蓝色。 提前致谢。
【问题讨论】:
我有一个 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
【讨论】: