NSTextField 与带有附件的 NSAttributedString 的奇怪行为
当我通过 NSAttributedString 将图像附件放置在 NSTextField 中时,当我单击它或更改它时,图像会消失。怎么了?
NSTextAttachment* attachment = [[NSTextAttachment alloc] init];
NSImage *symbolImage = [NSImage imageNamed:@"enabled.png"];
NSLog(@"%@", symbolImage);
NSTextAttachmentCell *anAttachmentCell = [[NSTextAttachmentCell
alloc] initImageCell:symbolImage];
[attachment setAttachmentCell:anAttachmentCell];
return [NSAttributedString attributedStringWithAttachment:attachment];
When I place image attachment in NSTextField via NSAttributedString, when I click it or change it, images disappears. What's wrong?
NSTextAttachment* attachment = [[NSTextAttachment alloc] init];
NSImage *symbolImage = [NSImage imageNamed:@"enabled.png"];
NSLog(@"%@", symbolImage);
NSTextAttachmentCell *anAttachmentCell = [[NSTextAttachmentCell
alloc] initImageCell:symbolImage];
[attachment setAttachmentCell:anAttachmentCell];
return [NSAttributedString attributedStringWithAttachment:attachment];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,修复方法非常简单。只需在需要显示图像的字段中启用“富文本”即可。
插入文本附件后,即使将焦点更改到另一个视图,图像也会保留在那里。
Actually, the fix is quite straight forward. Just enable "Rich Text" to the field where you need to display image.
Once text attachment is inserted, image remains there even after changing focus to another view.
billibala的上述答案也可以用代码实现。
对于
NSTextField
集The above answer by billibala can also be implemented in code.
For the
NSTextField
set