我正在尝试连接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)正在产生错误。我错过了什么?
发布于 2016-05-18 07:42:12
不允许更改NSAttributedString的内容,必须将附加到的字符串定义为可变的:
let str = NSMutableAttributedString()https://stackoverflow.com/questions/37293041
复制相似问题