objective-c - 带有附件的 NSAttributedString 的 NSTextField 的奇怪行为

标签 objective-c macos cocoa nsattributedstring

当我通过 NSAttributedString 在 NSTextField 中放置图像附件时,当我单击它或更改它时,图像会消失。怎么了?

NSTextAttachment* attachment = [[NSTextAttachment alloc] init];
NSImage *symbolImage = [NSImage imageNamed:@"enabled.png"];
NSLog(@"%@", symbolImage);
NSTextAttachmentCell *anAttachmentCell = [[NSTextAttachmentCell
                                           alloc] initImageCell:symbolImage];
[attachment setAttachmentCell:anAttachmentCell];
return [NSAttributedString attributedStringWithAttachment:attachment];

最佳答案

enter image description here

实际上,修复非常简单。只需在需要显示图像的字段启用“富文本”即可。

插入文本附件后,即使将焦点切换到另一个 View ,图像也会保留在那里。

关于objective-c - 带有附件的 NSAttributedString 的 NSTextField 的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8499526/

相关文章:

ios - Swift AVMutableVideoComposition指令规模

c - 无法在 macOS 中链接动态库

objective-c - 你如何在 NSTableView 中拖拽移动一行?

xcode - 无法对我的 Mac 应用程序进行签名以测试收据验证

objective-c - 命令/Developer/usr/bin/clang 失败,退出代码为 1

iphone - 在 NSString 中查找特定字符的位置

objective-c - 自定义UI分段控件

c++ - 如何使用 CMAKE 在 OSX 包中包含库

macos - 如何以编程方式在 macOS 上验证用户和密码?

objective-c - 绑定(bind)未更新。看不出出了什么问题