2017-01-19 8 views
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") 
     } 

    } 

} 

、ありがとう!

答えて

0

は私がしなければならなかったすべては

let attachmentCell = NSTextAttachmentCell(imageCell: img) 
textAttachment.attachmentCell = attachmentCell 

textAttachment.image = img 

を交換したが判明

関連する問題