Skip to content

Instantly share code, notes, and snippets.

@steipete
Created December 9, 2019 23:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steipete/9b279c94a35389c05bf5ea32336551ed to your computer and use it in GitHub Desktop.
Save steipete/9b279c94a35389c05bf5ea32336551ed 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