如何在iOS的WatchKit WKInterfaceLabel中加载HTML文本?

3

我有一个WKInterfaceLabel控件,无法加载HTML标签,例如

<h1>Grishneshwar Jyotirling</h1>

我无法使用NSMutableAttributedString,所以请帮忙找相关信息。

1个回答

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) ")
        }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接