问题描述
之前关于迁移到 iPhone 5 的帖子只提到添加新大小的启动图像*如果需要,可能会使用 AutoLayout.
The previous posting on here about migrating to iPhone 5 only mention adding a new sized launch image* and maybe using AutoLayout if need be.
但我有一些 xib,其中有一个背景图像,它填满了整个屏幕(可能会忽略导航和标签栏,具体取决于视图).为了支持 iPhone 5,我现在需要针对不同屏幕尺寸的不同图像,这在 xib 或其他地方是如何处理的?
But I have a few xibs where there is a background image which fills up the whole of the screen (maybe minue the navigation and tab bar, depending upon the view). To support iPhone 5 I will now need different images for the different screen size, how is this dealt with in the xib or elsewhere?
(*顺便说一句,如果应用不使用启动图像,你会怎么做?)
(*incidentally what do you do if the app doesn't use a launch image?)
推荐答案
这里有一个链接,对你有帮助.保存启动图像,如果您在文件名末尾输入-568h@2x.png",iOS 不会自动选择正确的图像.以上链接,这将使您的工作变得轻松.
Here's a link that will actually help you. Save the launch image, iOS doesn't automatically pick the right image if you put in a "-568h@2x.png" at the end of the file name. There are a couple of helper methods mentioned in the above link that will make your job easy.
我已经采用了上面提到的链接中的代码,这是 Obj-C 的辅助函数:
I have adopted the code in the links I mentioned above and here's the helper function for Obj-C:
-(BOOL) IsTall
{
return ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) && ([[UIScreen mainScreen] bounds].size.height * [[UIScreen mainScreen] scale] >= 1136);
}
写一点类别也会有所帮助.
A little category-writing would help too.
@interface NSString (Special)
-(NSString*)correctImageNameForiPhone5
@end
@implementation NSString (Special)
-(NSString*)correctImageNameForiPhone5
{
if([self isTall])
return -imageNameAppendedWith_-568h@2x.png_-; //Do the correct NSString magic here
else
return -originalImageName-;
}
@end
最后,当你访问 UIImage 对象时:
Finally, when you are accessing the UIImage object:
NSString *filename = @"backgroundImage.png";
UIImage *img = [UIImage imageNamed:[filename correctImageNameForiPhone5]];
这里的假设是您的所有 iPhone5 特定图像文件名都以-568h@2x"结尾.如果你只是把它放到你的项目中,这个代码示例肯定是行不通的,但你明白了.它需要一些 NSString 修复.
The assumption here is that you would have all your iPhone5-specific image file names ending with "-568h@2x". This code sample is definitely not gonna work if you just drop it into your project, but you get the idea. It needs some NSString fixes.
这篇关于在 iPhone5 和 iPhone4 的 xib 中处理不同尺寸的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!