Skip to content

Instantly share code, notes, and snippets.

@tmdvs
Created January 28, 2011 23:36
Show Gist options
  • Save tmdvs/801249 to your computer and use it in GitHub Desktop.
Save tmdvs/801249 to your computer and use it in GitHub Desktop.
@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