NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
NSImage *image = [NSImage imageNamed:@"emotion"];;
attachment.image = image;
NSAttributedString *attributedString = [NSAttributedString attributedStringWithAttachment: attachment];
[[_feedbackContent textStorage] appendAttributedString:attributedString];将图像添加到NSTextAttachment后,它是垂直翻转的。任何人都知道如何解决这个问题。
发布于 2019-01-10 15:56:42
NSTextAttachment似乎使用NSFileWrapper文件名来获取UTI,并且基于UTI有不同的行为。
我可以使用NSFileWrapper来解决这个问题:
NSFileWrapper *fileWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:data];
// Without a filename (which is used to get the UTI by NSTextAttachment)
// the image is displayed flipped.
[fileWrapper setPreferredFilename:@"Attachment.png"];
NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithFileWrapper:fileWrapper];您还可以尝试将fileType属性设置为kUTTypePNG或其他图像类型以使其正常工作。
雷达://47170950
发布于 2019-05-21 01:09:40
将映像分配给NSTextAttachmentCell,而不是NSTextAttachment。
id <NSTextAttachmentCell> cell = [[NSTextAttachmentCell alloc] initImageCell:image];
NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
[attachment setAttachmentCell:cell];发布于 2019-01-30 08:22:22
当绘制到翻转的视图时(这就是图像被翻转的原因),我发现的唯一解决办法是创建一个翻转的图像,然后将其绘制为:
textAttachment.image = [NSImage imageWithSize:image.size flipped:YES drawingHandler:^BOOL(NSRect dstRect) {
[image drawInRect:dstRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
return YES;
}];https://stackoverflow.com/questions/49649553
复制相似问题