Xcode 4.5 background image iPhone 4, 4s, 5

守給你的承諾、 提交于 2019-12-03 00:32:50

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

if you are trying to use [UIImage imageNamed:@"image.png"] and expect image-568h@2x.png to be picked automatically from the bundle for iPhone 5, it will not work. Automatic picking works only for iPhone 4 and 4S.

Only the Default image named as Default-568h@2x.png will be picked automatically in iPhone 5.

for normal images, if you have separate image for iPhone 5, try using this code

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

I believe it is incorrect to assume that you can apply the -568h@2x trick to all image files. I think it only works for Default-568h@2x.png. This is the file that iOS looks for at app launch on a 4" display device, as well as the "flag" to enable 4" display support in the SDK. For example, once you include this specific file, your table views will fill the screen.

I have not read anything to suggest that you can simply provide any image with the -568h@2x file name component and have it be used automagically. You'll have to do that yourself based on the screen size, e.g. [UIScreen mainScreen].bounds.size.height.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!