gpt4 book ai didi

objective-c - NSTextView 在文本之间插入图像

转载 作者:太空狗 更新时间:2023-10-30 03:21:10 24 4
gpt4 key购买 nike

是否可以将图像(不是背景图像)插入到 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com