是否可以将图像(不是背景图像)插入NSTextView
?
类似的东西:
Hi :) How are you?
它应该显示“笑脸”图像。我有NSTextView
和NSImage
。
答案 0 :(得分:36)
将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;