【问题标题】:How to display high resolution images in iOS4 using UIImageView如何使用 UIImageView 在 iOS4 中显示高分辨率图像
【发布时间】:2010-09-21 12:59:40
【问题描述】:

我想知道如何使用 UIImaageView 在 iOS4 sdk 中使用高分辨率图像。

blackBox = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"alert_bg.png"]];
blackBox.frame = CGRectMake(98.0f, 310.0f, 573.0f, 177.0f);

当我使用此代码时,我得到了奇怪的结果...图像的大小不正确。它在 iPhone 4 屏幕上看起来非常大。

我应该使用 326 ppi 图像吗?

我读过http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/SupportingResolutionIndependence/SupportingResolutionIndependence.html这个,但我很困惑。

谢谢

苏拉布

【问题讨论】:

    标签: ios4


    【解决方案1】:

    了解支持 Retina 显示屏的关键在于,在您的代码中,屏幕始终为 320x480。除了图像资源本身,您不需要将任何东西的分辨率加倍。在这种情况下,您只需在应用程序包中放入两个资源:一个适合 320x480 屏幕的 alert_bg.png(在这种情况下,我猜应该是 286x88)和一个 alert_bg@2x.png,正好是另一个尺寸,适合 640x960 的尺寸。如果你向 UIKit 询问[UIImage imageNamed:@"alert_bg"],它会自动为当前屏幕选择正确分辨率的资源。

    【讨论】:

      【解决方案2】:

      您应该为 3G、3GS 和原始 iPhone 提供一个 480x320 像素的图像,命名为“alert_bg.png”,为 iPhone 4 提供另一个 960x640 像素的图像,命名为“alert_bg@2x.png”。

      名称中的“@2x”由 iOS 自动添加,如果找到它会自动加载图像,而不是标准分辨率。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-10-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多