Reputation: 337
I am developing a wallpaper app, made solely for retina display iPhones. I have a 640 x 960 pixels sized image, legends.jpg
, that I want to display in a view, as a preview. Here's my code in loadView
:
- (void)loadView
{
// Init the main view first.
UIView *wallpaperContainerView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIImage *wallpaper = [UIImage imageNamed:@"legends.jpg"];
UIImageView *wallpaperView = [[UIImageView alloc] initWithImage:wallpaper];
[wallpaperContainerView addSubview:wallpaperView];
[self setView:wallpaperContainerView];
}
My questions are:
Thanks to the suggestions below, I created the legends.png (for non-retina) and [email protected] files. Then, I modified the *wallpaper
initialization to:
UIImage *wallpaper = [UIImage imageNamed:@"legends"];
This completely solves my #1 question. So apparently using JPG causes this scaling confusion, while with PNG everything works fine.
Upvotes: 0
Views: 691
Reputation: 917
Do not forget to manage Iphone 5 screens that have a height of 568.
Here is something that can be handy :
#define IS_PHONEPOD5() ([UIScreen mainScreen].bounds.size.height == 568.0f &&
[UIScreen mainScreen].scale == 2.f &&
UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
and
- (void)viewDidLoad
{
[super viewDidLoad];
if(IS_PHONEPOD5())
{
self.imageView.image = [UIImage imageNamed:@"image-568h@2x"];
}
else
{
self.imageView.image = [UIImage imageNamed:@"image"];
}
}
Upvotes: 1
Reputation: 293
You should always use @2x in the filename of the Retina version of your image.
And by the way, try to always use PNG format, as you won't have to bother in the future with filename extensions.
For instance, if you've got 2 files (normal and Retina with suffix @2x.png) you could simply write:
[UIImage imageNamed:@"legends"];
Upvotes: 1
Reputation: 5068
iPhone Retina screen is 3.5 inch but its resolution is double than non retina screens. So you have to include image resources for supporting both retina and non retina displays. Retina resource image name should have a suffix @2x. So include images with 320x480 (non retina) and 640x960 (retina) resolutions, your problem will get over.
Upvotes: 1