Created
September 25, 2012 14:44
-
-
Save carlj/3782351 to your computer and use it in GitHub Desktop.
iPhone 5 UIImage Category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (UIImage*)imageNamedForDevice:(NSString*)name { | |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) | |
{ | |
if (([UIScreen mainScreen].bounds.size.height * [UIScreen mainScreen].scale) >= 1136.0f) | |
{ | |
//Check if is there a path extension or not | |
if (name.pathExtension.length) { | |
name = [name stringByReplacingOccurrencesOfString: [NSString stringWithFormat:@".%@", name.pathExtension] | |
withString: [NSString stringWithFormat:@"-568h@2x.%@", name.pathExtension ] ]; | |
} else { | |
name = [name stringByAppendingString:@"-568h@2x"]; | |
} | |
//load the image e.g from disk or cache | |
UIImage *image = [UIImage imageNamed: name ]; | |
if (image) { | |
//strange Bug in iOS, the image name have a "@2x" but the scale isn't 2.0f | |
return [UIImage imageWithCGImage: image.CGImage scale:2.0f orientation:image.imageOrientation]; | |
} | |
} | |
} | |
return [UIImage imageNamed: name ]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you don't add the @2x modifier to the name, [UIImage imageNamed: name ]; will return an image with the correct scale.