是否可以在 NSTextView
中插入图像(不是背景图像)?
类似于:
你好 :) 你怎么样?
它应该显示一个“微笑”的图像。我有一个 NSTextView
和一个 NSImage
。
是否可以在 NSTextView
中插入图像(不是背景图像)?
类似于:
你好 :) 你怎么样?
它应该显示一个“微笑”的图像。我有一个 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;