I use bg.png for iPhone, bg@2x for both iPhone retina and iPad, bg@4x for iPad retina. Here is the code i wrote: (in Helper.m)
+ (UIImage *) imageNamed:(NSString *)name
{
name = [name stringByReplacingOccurrencesOfString:@".png" withString:@""];
UIImage *image;
if (IS_IPAD) {
if (IS_RETINA) {
image = [UIImage imageNamed:[NSString stringWithFormat:@"%@@4x.png", name]];
if (image) {
return image;
}
}
return [UIImage imageNamed:[NSString stringWithFormat:@"%@@2x.png", name]];
}
else {
if (IS_RETINA) {
image = [UIImage imageNamed:[NSString stringWithFormat:@"%@@2x.png", name]];
if (image) {
return image;
}
}
return [UIImage imageNamed:name];
}
}
The file is correct, but the size of image is wrong.
If the file is automatically picked by the system (use [UIImage imageNamed:@"bg.png"]
), then on iPhone retina, the size is still 320x480 (1 point = 4 pixels).
but if i use [Helper imageNamed:@"bg.png"]
, the size is 640x960. (1 point = 1 pixel)
So anyway to correct the size?