【问题标题】:How to load html text in watchkit WKInterfaceLabel in ios?如何在ios的watchkit WKInterfaceLabel中加载html文本?
【发布时间】:2016-05-16 06:31:13
【问题描述】:

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

<h1>Grishneshwar Jyotirling</h1>

我不能使用 NSMutableAttributedString,所以请帮我查找相关内容。

【问题讨论】:

    标签: html ios iphone watchkit nsattributedstring


    【解决方案1】:
     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) ")
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多