我正在尝试为OS X应用程序创建一个包含NSAttributedString
的{{1}}。
我尝试了几种不同的方法,但使用这个基本代码:
NSImage
当我在NSLabel或NSTextField属性字符串上设置它时,图像不会渲染。
是否可以将let image = NSImage(named: "super-graphic")!
let attachment = NSTextAttachment()
attachment.image = image
let imageString = NSAttributedString(attachment: attachment)
和NSImage
合并在OS X上的属性字符串中嵌入图像?
答案 0 :(得分:0)
嗯,我感到愚蠢,这段代码有效:
let image = NSImage(named: "super-graphic")!
let attachment = NSTextAttachment()
let cell = NSTextAttachmentCell(imageCell: image)
attachment.attachmentCell = cell
let imageString = NSAttributedString(attachment: attachment)
关键区别在于避免使用"图像" NSTextAttachment