如何在ios中的watchkit WKInterfaceLabel中加载html文本?

时间:2016-02-06 07:11:36

标签: html ios iphone watchkit nsattributedstring

我在WKInterfaceLabel上,我无法加载HTML标签,如

<h1>Grishneshwar Jyotirling</h1>

我不能使用NSMutableAttributedString所以请帮我找一些事情。

1 个答案:

答案 0 :(得分:0)

 var htmlText = "<h1>Grishneshwar Jyotirling</h1> Grishneshwar Jyotirling"
    let attributeText: NSAttributedString?

    if let htmlData = htmlText.dataUsingEncoding(NSUnicodeStringEncoding) {

        do {

            attributeText  =  try   NSAttributedString(data: htmlData , options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
            myLabel.setAttributedText(attributeText)

        }catch let e as NSError {
            print("Couldn't translate \(htmlText): \(e.localizedDescription) ")
        }