是否可以将图像(不是背景图像)插入到 NSTextView
中?
像这样的东西:
Hi :) How are you?
它应该显示一个“笑脸”图像。我有一个 NSTextView
和一个 NSImage
。
最佳答案
将 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;
关于objective-c - NSTextView 在文本之间插入图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5300427/