Skip to content

Instantly share code, notes, and snippets.

@agassiyzh
Created November 21, 2011 00:23
Show Gist options
  • Save agassiyzh/1381253 to your computer and use it in GitHub Desktop.
Save agassiyzh/1381253 to your computer and use it in GitHub Desktop.
@implementation UIImage (TPAdditions)
-(id)initWithContentsOfResolutionIndependentFile:(NSString*)path {
if([[[UIDevice currentDevice] systemVersion] intValue] >=4&&[[UIScreen mainScreen] scale]==2.0){
NSString*path2x =[[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@@2x.%@", [[path lastPathComponent] stringByDeletingPathExtension], [path pathExtension]]];
if([[NSFileManager defaultManager] fileExistsAtPath:path2x]){
return[self initWithCGImage:[[UIImage imageWithData:[NSData dataWithContentsOfFile:path2x]] CGImage] scale:2.0 orientation:UIImageOrientationUp];
}
}
return[self initWithData:[NSData dataWithContentsOfFile:path]];
}
+(UIImage*)imageWithContentsOfResolutionIndependentFile:(NSString*)path {
return[[[UIImage alloc] initWithContentsOfResolutionIndependentFile:path] autorelease];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment