Skip to content

Instantly share code, notes, and snippets.

@seikai
Created September 30, 2013 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seikai/6759130 to your computer and use it in GitHub Desktop.
Save seikai/6759130 to your computer and use it in GitHub Desktop.
UIImage *image;
NSMutableString *imageName = [[NSMutableString alloc] initWithString:@"Default"];
BOOL isPad = ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad );
if( isPad )
{
BOOL isLandscape = UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]);
NSString *imageOrientation = (isLandscape) ? @"Landscape" : @"Portrait";
BOOL isRetina = ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0);
NSString *scaleString = (isRetina) ? @"@2x" : @"";
// Default-Landscape~ipad.png
// Default-Landscape@2x~ipad.png
// Default-Portrait~ipad.png
// Default-Portrait@2x~ipad.png
imageName = [NSMutableString stringWithFormat:@"%@-%@%@~ipad.png", imageName, imageOrientation, scaleString ];
} else {
if( CGRectGetHeight(self.view.frame) > 480.f)
{
// Default-568h.png
imageName = [NSMutableString stringWithFormat:@"%@-568h.png", imageName];
} else {
// Default.png
// Default@2x.png
imageName = [NSMutableString stringWithFormat:@"%@.png", imageName];
}
}
image = [UIImage imageNamed:imageName];
@seikai
Copy link
Author

seikai commented Sep 30, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment