我正在将我的项目升级到 Xcode 16。当使用以下函数时,它可以在 Xcode 15 上正确渲染,但不在 Xcode 16 上。
// The label created with `attributedText`.
let label = UILabel()
label.attributedText = self.init(html: "<ol><li>1th item</li><li>2th item</li><li>3rd item</li></ol>")
// The convenience function to init html `NSAttributedString` with a string instead of data.
extension NSAttributedString {
public convenience init(html: String) {
guard let encodedData = html.data(using: String.Encoding.utf16) else {
print("Unable to encode html string to data")
self.init(string: html)
return
}
assert(Thread.isMainThread, "The HTML importer should not be called from a background thread!")
do {
try self.init(
data: encodedData,
options: [
.documentType: NSAttributedString.DocumentType.html,
.characterEncoding: String.Encoding.utf16.rawValue,
],
documentAttributes: nil
)
} catch {
print("Initialising NSAttributedString with html failed \(error)")
self.init()
}
}
}
有人面临同样的问题吗?
我确实期望列表的数字(预期结果) 使用基于“html”的“NSAttributedString”时会呈现项目。但对于 Xcode 16,它不起作用。它没有显示列表点。 (实际结果)