0
NSMutableAttributedStringにNSTextAttachmentを使用してイメージを追加しようとしていますが、アプリケーションを再起動するまでイメージが表示されないようです。何か案は?その後イメージを含むNSTextAttachmentをNSMutableAttributedStringに追加するとすぐに表示されません。
let r = NSMakeRange(loc, len)
attributedString?.addAttributes(attributesForThisSection, range: r)
テキストはNSTextViewに表示され
var attributesForThisSection = [String : Any]()
if key == NSAttachmentAttributeName {
let base64Rep = (value as! String)
if let data = Data(base64Encoded: base64Rep) {
let textAttachment = NSTextAttachment()
if let img = NSImage(data: data) {
textAttachment.image = img
attributesForThisSection[NSAttachmentAttributeName] = textAttachment
}
else {
print("img from data not ok")
}
}
}
、ありがとう!