Created
January 28, 2011 23:36
-
-
Save tmdvs/801249 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@implementation UIApplication(Retina) | |
- (BOOL) deviceIsRetina | |
{ | |
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00) { | |
// RETINA DISPLAY | |
return YES; | |
} | |
else | |
{ | |
return NO; | |
} | |
} | |
@end | |
@implementation UIImage(Retina) | |
+ (UIImage *)imageNamed:(NSString *)name | |
{ | |
if([[UIApplication sharedApplication] deviceIsRetina]) | |
{ | |
NSArray *file = [name componentsSeparatedByString:@"."]; | |
NSString *retinaName = [NSString stringWithFormat:@"%@@2x", [file objectAtIndex:0]]; | |
return [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:retinaName | |
ofType:[file objectAtIndex:1]]]; | |
} | |
else | |
{ | |
NSArray *file = [name componentsSeparatedByString:@"."]; | |
return [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[file objectAtIndex:0] | |
ofType:[file objectAtIndex:1]]]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment