Reputation: 14404
How do I properly use standard and retina display icons in iOS? Do I need to detect the resolution of the device? If so, what is the best procedure to do this. Do I need to do something similar to the follow?
UINavigationBar *navbar...
NSString *imageName;
if (isRetinaDisplay)
{
imageName = @"[email protected]";
}
else
{
imageName = @"hello.png";
}
navbar.tabBarItem.image = [UIImage imageNamed:imageName];
Any suggestions would be appreciated. Thank you.
Upvotes: 3
Views: 2427
Reputation: 75
The main thing for using normal and retina images is that you should take care of naming convention as well image size. Example:-if your icon size is 52*52 and name is icon.png(for normal),then your retina image size and naming convention should be like [email protected] 104*104. Hope it might be helpful. Thanks
Upvotes: 1
Reputation: 5765
imageNamed automatically does this for you. All you have to do is use the proper nomenclature for the images you incluse in your project, and imageNamed will pick the suitable image on the basis of the device your application is running on.
Upvotes: 1
Reputation: 118681
No, you don't. iOS will automatically detect and use @2x
images on hi-res devices. Check out the Drawing and Printing Guide for more information. An excerpt:
On devices with high-resolution screens, the
imageNamed:
,imageWithContentsOfFile:
, andinitWithContentsOfFile:
methods automatically looks for a version of the requested image with the@2x
modifier in its name. It if finds one, it loads that image instead. If you do not provide a high-resolution version of a given image, the image object still loads a standard-resolution image (if one exists) and scales it during drawing.
Upvotes: 7