Skip to content

Instantly share code, notes, and snippets.

@steipete
Created December 9, 2019 23:15
Show Gist options
  • Save steipete/ed0fd2dfe821a591e68d075d2d80750e to your computer and use it in GitHub Desktop.
Save steipete/ed0fd2dfe821a591e68d075d2d80750e to your computer and use it in GitHub Desktop.
@implementation UIImage (ResourceProxyHack)
+ (UIImage *)_iconForResourceProxy:(id)proxy format:(int)format {
// HACK: proxy seems garbage so we always show PDF for now.
let cgImage = [_bridge imageForFileType:@"pdf"];
// HACK: We use mainScreen here but could have multiple screens.
let image = [UIImage imageWithCGImage:cgImage scale:UIScreen.mainScreen.scale orientation:UIImageOrientationUp];
return image;
}
@end
// In the AppKit bridge:
- (CGImageRef)imageForFileType:(NSString *)fileType {
NSImage *image = [NSWorkspace.sharedWorkspace iconForFileType:fileType];
image.size = NSMakeSize(16, 16);
CGImageRef cgRef = [image CGImageForProposedRect:NULL context:nil hints:nil];
return cgRef;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment