【问题标题】:NSTextView insert image in between textNSTextView 在文本之间插入图像
【发布时间】:2011-07-15 02:23:06
【问题描述】:

是否可以在NSTextView 中插入图像(不是背景图像)? 比如:

嗨 :) 你好吗?

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

【问题讨论】:

  • 你找到如何在 nstextview 中添加复选框或其他东西了吗?
  • 我没有寻找复选框,我只需要插入图像,我相信,使用 NSTextView 应该是可行的

标签: objective-c cocoa macos nstextview nsimage


【解决方案1】:

将 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;

【讨论】:

  • 非常感谢,还有一个问题是有什么方法可以添加更多控件,例如,如果我想在用户想要传输文件时添加进度条
  • 谢谢!您知道如何提供带有单元格图像的拖放功能吗?默认情况下,如果我将它拖到 Finder,它会创建一个空文本文件
猜你喜欢
  • 1970-01-01
  • 2019-02-03
  • 1970-01-01
  • 2012-02-26
  • 2017-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-14
相关资源
最近更新 更多