Xcode 16中NSAttributedString渲染HTML有序列表异常求助
Xcode 16中NSAttributedString解析HTML有序列表丢失编号的问题
我正在把项目升级到Xcode 16,使用自定义的NSAttributedString扩展从HTML初始化富文本时遇到了问题:在Xcode 15中能正常渲染<ol><li>的有序列表(显示带编号的列表项),但Xcode 16里只显示列表项内容,完全看不到编号。
相关代码如下:
// 使用attributedText创建的标签 let label = UILabel() label.attributedText = self.init(html: "<ol><li>1th item</li><li>2th item</li><li>3rd item</li></ol>") // 用字符串而非数据初始化HTML格式NSAttributedString的便利方法 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解析后的富文本能正常显示有序列表的编号,实际效果却只有列表项文本,编号完全缺失。
想问下有没有其他开发者遇到过同样的问题?
内容的提问来源于stack exchange,提问作者user3297288
相关产品推荐
相关产品推荐

