gpt4 book ai didi

ios - 连接 2 个 NSAttributedString

转载 作者:行者123 更新时间:2023-11-28 12:48:31 24 4
gpt4 key购买 nike

我正在尝试连接 2 个 NSAttributedString。但它给我的错误是该方法不可用,而该方法可用。这是我的代码:

let def = "I am using here <ul><li>Coffee</li><li>Tea</li><li>Milk</li></ul> <br/> <a href='http://www.w3schools.com'>Visit W3Schools.com</a>"

do {

definition.delegate = self
definition.editable = false

let str = try NSAttributedString(data: def.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!, options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)

let textAttachment = NSTextAttachment()
textAttachment.image = UIImage(named: "clip_image002.jpg")

let str2 = NSAttributedString(attachment: textAttachment)

str.appendAttributedString(str2)

definition.attributedText = str


} catch {
print(error)
}

基本上 str.appendAttributedString(str2) 会产生错误。我缺少什么?

最佳答案

你不能改变 NSAttributedString 的内容,你必须定义你追加的字符串为可变的:

let str = NSMutableAttributedString()

NSMutableAttributedString

关于ios - 连接 2 个 NSAttributedString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37293041/

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