NSTextView在文本之间插入图像 [英] NSTextView insert image in between text
本文介绍了NSTextView在文本之间插入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 NSTextView
中插入图片(而不是背景图片)?
类似:
Is it possible to insert an image (not a background image) into an NSTextView
?
Something like:
Hi :) How are you?
它应该显示一个笑脸的图像。我有一个 NSTextView
和 NSImage
。
and it should display a "smiley" image. I have an NSTextView
and an NSImage
.
推荐答案
将NSImage插入NSTexView:
Insert NSImage into NSTexView:
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;
这篇关于NSTextView在文本之间插入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文