// 将字符值引用转位普通字符串
var htmlToString: String {
do {
let encodedData = self.data(using: String.Encoding.utf8)!
let attributedOptions:[NSAttributedString.DocumentReadingOptionKey : Any] = [
NSAttributedString.DocumentReadingOptionKey(rawValue: NSAttributedString.DocumentAttributeKey.documentType.rawValue) :NSAttributedString.DocumentType.html,
NSAttributedString.DocumentReadingOptionKey(rawValue: NSAttributedString.DocumentAttributeKey.characterEncoding.rawValue): String.Encoding.utf8.rawValue
]
let attributedString = try NSAttributedString(data: encodedData,
options: attributedOptions, documentAttributes: nil)
return attributedString.string
} catch {
fatalError("Unhandled error: \(error)")
}
return ""
}
```复制代码
使用webView加载网页标签转码的问题
最新推荐文章于 2022-03-29 17:50:44 发布