NSTextAttachment的图像根本不显示.但是,它似乎仍然设置正确.因为复制NSTextVIEw的内容并将其粘贴回例如TextEdit.app,粘贴的文本正确包含图像.
这是一个重现这个问题的最小游乐场:
import Cocoalet img = NSImage(named: "Checked")let textVIEw = NSTextVIEw(frame: NSMakeRect(0,254,64))let attrstr = NSMutableAttributedString(string: "Test")let attch = NSTextAttachment()attch.image = imgattrstr.appendAttributedString(NSAttributedString(attachment: attch))textVIEw.textStorage!.setAttributedString(attrstr)textVIEw
预期产量:
对于iOS,所以使用UIKit而不是Cocoa,它可以很好地工作:
import UIKitlet img = UIImage(named: "Checked")let textVIEw = UITextVIEw(frame: CGRectMake(0.0,0.0,200.0,44.0))let attrstr = NSMutableAttributedString(string: "Test")let attch = NSTextAttachment()attch.image = imgattrstr.appendAttributedString(NSAttributedString(attachment: attch))textVIEw.attributedText = attrstrtextVIEw
我正在使用XCode 7.两个游乐场都可以下载here.
任何想法都非常欢迎,提前致谢!
@H_404_39@解决方法var thumbnailImage: NSImage? = // some imagevar attachmentCell: NSTextAttachmentCell = NSTextAttachmentCell.initimageCell(thumbnailImage!)var attachment: NSTextAttachment = NSTextAttachment()attachment.attachmentCell = attachmentCellvar attrString: NSAttributedString = NSAttributedString.attributedStringWithAttachment(attachment)self.textVIEw.textStorage().appendAttributedString(attrString)总结
以上是内存溢出为你收集整理的ios – NSTextAttachment图像未在NSTextView中显示(但在UITextView中)?全部内容,希望文章能够帮你解决ios – NSTextAttachment图像未在NSTextView中显示(但在UITextView中)?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)