-->

xcode的4.5背景图像iPhone 4,4S,5(Xcode 4.5 background im

2019-08-01 22:16发布

我在写viewController.m后台代码:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]];

和我有不同的图片的正确名称:

image.png for non-retina display (320x480)

image@2x.png for retina display (640x960)

image-568h@2x.png for iPhone 5 (640x1136)

但是,当我在模拟器中运行它,它并不需要为iPhone 5屏幕image-568h@2x.png只需要4秒屏幕上的图像@ 2x和缩放以适应屏幕...我不知道是否有任何编码用于iPhone 5的屏幕图像568h @ 2倍?

即时通讯使用的Xcode 4.5

Answer 1:

iPhone 5是视网膜,就像iPhone 4和4S,以及@ 2X-图像将自动所有这些设备中使用。 这是唯一的启动图像被称为“-568h @ 2X”的iPhone 5.您需要编写一些代码来使用不同的图像,像这样的工作:

NSString *filename = @"image.png";
CGRect screenRect = [[UIScreen mainScreen] bounds];
if (screenRect.size.height == 568.0f)
    filename = [filename stringByReplacingOccurrencesOfString:@".png" withString:@"-568h.png"];

imageView.image = [UIImage imageNamed:filename];


Answer 2:

如果你要使用[UIImage imageNamed:@"image.png"]并期望image-568h@2x.png自动从捆绑的iPhone 5被挑选,这是行不通的。 自动拾取仅适用于iPhone 4和4S。

只有命名为默认图像Default-568h@2x.png会自动在iPhone 5进行采摘。

为正常图像,如果你有单独的图像为iPhone 5,尝试使用此代码

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
    // code for 4-inch screen
} else {
    // code for 3.5-inch screen
}


Answer 3:

我认为这是不正确的假设,你可以将-568h@2x的所有图像文件。 我认为它适用于Default-568h@2x.png 。 这是iOS的查找文件在4" 应用程序启动显示设备,以及在‘标志’,使4" 中的SDK显示支持。 例如,一旦你包含这个特定的文件,你的表视图将充满整个屏幕。

我没有读过什么建议,你可以简单地提供与任何图像-568h@2x文件名组件并已将其被自动地使用。 您就有了自己根据屏幕大小,例如做[UIScreen mainScreen].bounds.size.height



文章来源: Xcode 4.5 background image iPhone 4, 4s, 5