gpt4 book ai didi

swift - 具有字体大小和 HTML 标记属性的 NSMutableAttributedString

转载 作者:行者123 更新时间:2023-11-28 08:19:52 25 4
gpt4 key购买 nike

<分区>

我在使用 NSMutableAttributedString 时遇到问题为了读取 HTML 字符串并增加其字体大小。

输入 HTML:<b>Lorem ipsum</b> dolor sit <i>amet</i></h3>consectetuer</h3> adipiscing elit

NSMutableAttributedString转换如下:

let htmlData = input.data(using: .utf8)!

let htmlAttrs = [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute:String.Encoding.utf8.rawValue] as [String : Any]

do{
let new = try NSMutableAttributedString(data: htmlData, options: htmlAttrs, documentAttributes: nil)

let tillEnd = NSRange(location: 0, length: new.length)
let attr:UIFont = UIFont.systemFont(ofSize: 25)

//new.addAttribute(NSFontAttributeName, value: attr, range: tillEnd)

textView.attributedText = new
}

它正确读取 HTML 标签并给出输出

HTML properly encoded .

但是如果我想增加字体大小并取消注释 addAttribute , 字体大小增加但不呈现 HTML。

font size increase but html reading gone

我可以将字符串与字体大小和 HTML 渲染一起使用吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com