开发者

How to use normal and retina display icons for iOS

How do I properly use standard and re开发者_C百科tina 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.


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 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜