2

我正在声明一个 NSMutable 属性字符串并向其附加不同的属性字符串。这些属性字符串可能包含图像作为 NSTextattachments。

var historyText : NSMutableAttributedString = NSMutableAttributedString(string: "")
let imageAttachment = NSTextAttachment()
imageAttachment.image = UIImage(named: "some_image")
imageAttachment.bounds = CGRect(x:0, y:-3.0, width:    (imageAttachment.image?.size.width)!, height:(imageAttachment.image?.size.height)!)
let imageString = NSAttributedString(attachment: imageAttachment)
historyText.append(imageString)

然后我将这个属性文本保存在核心数据中。但是,当我从核心数据中检索此属性文本时, imageAttachment.bounds 会丢失。请提出一种保留这些界限的方法。提前致谢。

4

0 回答 0