Skip to content

Instantly share code, notes, and snippets.

@octover
Last active August 29, 2015 14:16
Show Gist options
  • Save octover/03d45247b2fe06aab164 to your computer and use it in GitHub Desktop.
Save octover/03d45247b2fe06aab164 to your computer and use it in GitHub Desktop.
imageNamed from a specific bundle
// This isn't documented to handle @2x, but it appears to in practice
// Had to put all images in a bundle so something like this:
image = [UIImage imageNamed:@"rounded_button.png"];
// became:
NSURL *url = [[NSBundle mainBundle] URLForResource:@"BruffLiteResources" withExtension:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithURL:url];
NSString *imagePath = [bundle pathForResource:@"share" ofType:@"png"];
image = [UIImage imageWithContentsOfFile:imagePath];
// passing nil to compatibleWithTraitCollection uses the main screen's traits (so @2x @3x are picked up)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment