小编She*_*eem的帖子

在 UITextView 中显示 HTML 内容

我想使用 swift 在 UITextView 控件中显示字符串 HTML。我找到了一些代码并尝试了一下:

     do {
        let str = try NSAttributedString(data: htmlString.data(using: String.Encoding.unicode, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType], documentAttributes: nil)
    } catch {
        print(error)
    }
Run Code Online (Sandbox Code Playgroud)

但我给出了一些我无法理解或找到任何解决方案的错误,其中指出,

无法将“NSAttributedString.DocumentAttributeKey”类型的值转换为预期的字典键类型“NSAttributedString.DocumentReadingOptionKey”

我需要弄清楚为什么我会遇到这个错误。任何解决方案或替代代码?其他解决方案在objective-c中,如果他们有答案,他们会给出同样的错误,我试过很多只是因为旧版本。

ios swift

4
推荐指数
1
解决办法
7236
查看次数

标签 统计

ios ×1

swift ×1