NSTextView 在文本中插入图片

13

是否可以在 NSTextView 中插入图像(不是背景图像)? 类似于:

你好 :) 你怎么样?

它应该显示一个“微笑”的图像。我有一个 NSTextView 和一个 NSImage


你找到了如何将复选框或其他内容添加到NSTextView中吗? - NeXT5tep
我没有寻找复选框,我只需要插入图像,我相信使用NSTextView应该是可行的。 - Amitg2k12
1个回答

37

将 NSImage 插入到 NSTextView 中:

NSImage * pic = [[NSImage alloc] initWithContentsOfFile:@"/Users/Anne/Desktop/Sample.png"];
NSTextAttachmentCell *attachmentCell = [[NSTextAttachmentCell alloc] initImageCell:pic];
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
[attachment setAttachmentCell: attachmentCell ];
NSAttributedString *attributedString = [NSAttributedString  attributedStringWithAttachment: attachment];
[[textView textStorage] appendAttributedString:attributedString];
在头文件中:
IBOutlet id textView;

非常感谢,还有一个问题,是否有任何方法可以添加更多的控件,例如,如果我想在用户想要传输文件时添加进度条? - Amitg2k12
谢谢!您知道如何提供带有单元格图像的拖放功能吗?默认情况下,如果我将其拖到Finder中,它会创建一个空文本文件。 - hyouuu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接