Xcode 4.5背景图片iPhone 4,4s,5 [英] Xcode 4.5 background image iPhone 4, 4s, 5

查看:94
本文介绍了Xcode 4.5背景图片iPhone 4,4s,5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在viewController.m中写了背景代码:

I have in my viewController.m written the background code:

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

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

And I have the correct names of the different pictures:

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的模拟器它只需要图像@ 2x用于4s屏幕并缩放它以适应屏幕...我不知道是否有任何编码使用图像-568h @ 2x for iPhone 5 screen?

But when I run it in the simulator it does not take the image-568h@2x.png for iPhone 5 screen it only takes the image@2x for 4s screen and scale it to fit the screen... I dont know if there is any coding to use the image-568h@2x for iPhone 5 screen?

我正在使用Xcode 4.5

Im using Xcode 4.5

推荐答案

iPhone 5是视网膜,就像iPhone 4和4S一样,@ 2x图像将自动用于所有这些设备。对于iPhone 5,它只是一个名为-568h @ 2x的启动图像。你需要编写一些代码来使用不同的图像,这样的东西可以工作:

iPhone 5 is retina, just like iPhone 4 and 4S, and the @2x-image will be used automatically for all these devices. It's only the startup-image that is called "-568h@2x" for iPhone 5. You need to write some code to use a different image, something like this would work:

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

这篇关于Xcode 4.5背景图片iPhone 4,4s,5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆