简体   繁体   中英

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 = @"hello@2x.png";
}
else
{
    imageName = @"hello.png";
}

navbar.tabBarItem.image = [UIImage imageNamed:imageName];

Any suggestions would be appreciated. Thank you.

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.

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 icon@2x.png 104*104. Hope it might be helpful. Thanks

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM