I know there were some discussions about this but i could not find good answer?
My questions are -
I know that -
[UIImage imageNam
Maybe you can duplicate all images resources image@2x.png to image~ipad.png. Be careful to the case of "~ipad.png". But you have to manually manage stretched image with Cap (stretchableImageWithLeftCapWidth: topCapHeight:).
If you're loading an image named "image" the search paths are likely to be the same as they've always been:
iPhone:
iPad:
There is no good built-in way of not duplicating the higher res iphone retina images for the iPad. You could write your own UIImage extension or subclass that uses the user interface idiom macro to determine your platform, then automatically append "@2x" to the image name:
+ (UIImage *) imageNamedSmart:(NSString *)name
{
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
return [UIImage imageNamed:[NSString stringWithFormat:@"%@@2x.png", name]];
return [UIImage imageNamed:[NSString stringWithFormat:@"%@.png", name]];
}
and you'd call it like this:
[UIImage imageNamedSmart:@"myImage"]
I improved on Bogatyr's answer by checking if the retina image exists. Probably not overly necessary, but I found it useful when testing so I can just create one image file.
+ (UIImage *) imageNamedSmart:(NSString *)name {
NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];
NSString *retinaFileName = [NSString stringWithFormat:@"%@@2x", name];
NSString *filePath = [[NSBundle mainBundle] pathForResource:retinaFileName ofType:@"png"];
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && [fileManager fileExistsAtPath:filePath]) {
return [UIImage imageNamed:[retinaFileName stringByAppendingString:@".png"]];
}
return [UIImage imageNamed:[NSString stringWithFormat:@"%@.png", name]];
}