David
David

Reputation: 14404

How to use normal and retina display icons for iOS

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

Answers (3)

user1240409
user1240409

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

Akshay
Akshay

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

jtbandes
jtbandes

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:, and initWithContentsOfFile: 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

Related Questions