当我通过 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];
最佳答案
实际上,修复非常简单。只需在需要显示图像的字段启用“富文本”即可。
插入文本附件后,即使将焦点切换到另一个 View ,图像也会保留在那里。
关于objective-c - 带有附件的 NSAttributedString 的 NSTextField 的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8499526/