如何使用UIImageView在iOS4中显示高分辨率图像 [英] How to display high resolution images in iOS4 using UIImageView
问题描述
我想知道如何使用UIImaageView在iOS4 sdk中使用高分辨率图像。
I wanted to know how should I use high res images in iOS4 sdk using UIImaageView.
blackBox = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"alert_bg.png"]];
blackBox.frame = CGRectMake(98.0f, 310.0f, 573.0f, 177.0f);
当我使用此代码时,我得到奇怪的结果......图像的大小不正确。它在iPhone 4屏幕上看起来非常大。
When I use this code I get strange results... the image does not get the correct size. It is looking very big on iPhone 4 screen.
我应该使用326 ppi图像吗?
Should I use 326 ppi images?
谢谢
Saurabh
推荐答案
关于支持Retina显示屏的关键要点是,在您的代码中,屏幕始终为320x480 。除了图像资源本身之外,您不需要将任何分辨率加倍。在这种情况下,您只需要在应用程序包中放置两个资源:一个适合320x480屏幕的 alert_bg.png
- 在这种情况下,我猜这个' d为286x88,而 alert_bg@2x.png
,正好是另一个的两倍,适合640x960。如果您向UIKit询问 [UIImage imageNamed:@alert_bg]
,它会自动为当前屏幕选择正确分辨率的资源。
The key thing to understand about supporting the Retina Display is that, in your code, the screen is always 320x480. You don't need to double the resolution of anything but your image resources themselves. In this case, you just need to put two resources in your app bundle: an alert_bg.png
that fits on a 320x480 screen—in this case, I'd guess that'd be 286x88—and an alert_bg@2x.png
, exactly double the size of the other, that fits on a 640x960 one. If you ask UIKit for [UIImage imageNamed:@"alert_bg"]
, it'll automatically pick the correct-resolution resource for the current screen.
这篇关于如何使用UIImageView在iOS4中显示高分辨率图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!