iOS的Colorwithpattern - 使用自定义图像的iPhone5 [英] iOS Colorwithpattern - using a custom iPhone5 image

查看:119
本文介绍了iOS的Colorwithpattern - 使用自定义图像的iPhone5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我的应用程序的载入画面和闪屏,我用了两个不同的方法来适当地显示我的iPhone 3,iPhone 4和iPhone 5的图片。

For my app's loading screen and splash screen, I used up with two different methods to display my iPhone 3, iPhone 4 and iPhone 5 images appropriately.

有关加载屏幕,简单地增加-568h @ 2到你的形象,就足以支持iPhone5的。

For the loading screen, simply adding -568h@2x to your image is enough to support iPhone5.

有关的启动画面,我用了一系列的(如果高度==)案件检查UIScreen边界的高度和采购适当的图像输出到图像视图。很明显我这里说的-568h并没有被普遍公认的iPhone 5的图像。它仅适用于载入画面。

For the splashscreen, I used a series of (if height == ) cases to check the height of the UIScreen's bounds and sourced the appropriate image to the image view. It was apparent to me here that the -568h isn't universally recognized as an iPhone 5 image. It is only applicable to the loading screen.

现在,在我的AppDelegate,我设置一个背景图像。我所有的子视图有一个透明的背景,所以他们应该通过展现给背景图像。不过,我有最麻烦的在这里设置的背景图像。

Now, in my AppDelegate, I'm setting a the background image. All my subviews have a transparent background, so they are supposed to show through to the background image. However, I am having the most trouble setting up the background image here.

只需在Background.png通过添加-568h @ 2倍到文件名末尾不起作用。它会做非视网膜和3.5''的Retina显示屏,但不会拿起4''显示。

Simply passing in the "Background.png" Adding the -568h@2x to the end of the filename does not work. It will do the non-retina and the 3.5'' retina display, but will not pick up for the 4'' display.

例如:

self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background.png"]];

如果我用code以上片段中,iPhone4的图片是用来代替iPhone5的图片,这不是我想要的。

If I use the above snippet of code, the iPhone4 picture is used instead of the iPhone5 picture and this is not what I want.

我走上了试图做同样的事情,我的启动画面做了。我有一堆的,如果情况:

I moved onto trying to do the same thing as I did with the splashscreen. I had a bunch of if cases:

CGFloat height = [UIScreen mainScreen].currentMode.size.height;

if ( height == 1136 )
{
     //Choose image here
}
else if (height == 960)
{
     //Choose image here
}
else if (height == 480)
{
     //Choose image here
}
self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:chosenImage]];

但colorWithPatternImage函数认为,chosenImage推移1分= 1个像素。所以,我结束了一个非视网膜图像试图以适合iPhone 5的屏幕。它看起来是什么样exaclty?貌似只有我想显示在整个iPhone 5的屏幕上的图像的左上方象限。它看起来像没有施加视网膜缩放。

But the colorWithPatternImage function thinks that the chosenImage goes by 1 point = 1 pixel. So I end up with a non-retina picture attempting to fit onto the iPhone 5 screen. What exaclty does it look like? Looks like only the top left quadrant of the image I wanted is displayed over the entire iPhone 5 screen. It looks like no retina scaling was applied.

我需要iPhone的认识到,我有一个视网膜友好的iPhone 5的图片作为背景。我该怎么做呢?

I need the iPhone to recognize that I have a retina-friendly iPhone 5 picture to be used as the background. How do I do this?

推荐答案

我发现这个code <一个href=\"http://alexanderwong.me/post/32365780864/iphone-5-retina-4-detection-and-asset-modifiers\">here,也许它可以帮助你:

I found this code here, perhaps it helps you:

UIImage *tmpImage = [UIImage imageNamed:@"background-568h@2x.png"];
UIImage *backgroundImage = [UIImage imageWithCGImage:[tmpImage CGImage]
                                               scale:2.0
                                         orientation:UIImageOrientationUp];
self.window.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];

这篇关于iOS的Colorwithpattern - 使用自定义图像的iPhone5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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