gpt4 book ai didi

image - iOS Colorwithpattern - 使用自定义 iPhone5 图像

转载 作者:行者123 更新时间:2023-12-04 14:47:37 24 4
gpt4 key购买 nike

对于我的应用程序的加载屏幕和启动屏幕,我使用了两种不同的方法来适本地显示我的 iPhone 3、iPhone 4 和 iPhone 5 图像。

对于载入画面,只需在图像中添加 -568h@2x 就足以支持 iPhone5。

对于闪屏,我使用了一系列(如果 height == )案例来检查 UIScreen 边界的高度,并将适当的图像提供给 ImageView 。在这里我很明显,-568h 并没有被普遍认为是 iPhone 5 图像。它仅适用于加载屏幕。

现在,在我的 AppDelegate 中,我正在设置背景图像。我所有的 subview 都有透明背景,所以它们应该显示到背景图像。但是,我在这里设置背景图像时遇到了最大的麻烦。

简单地传入“Background.png” 将 -568h@2x 添加到文件名的末尾是行不通的。它将支持非视网膜和 3.5 英寸视网膜显示屏,但不会支持 4 英寸显示屏。

IE:

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

如果我使用上面的代码片段,则使用 iPhone4 图片而不是 iPhone5 图片,这不是我想要的。

我继续尝试做与启动屏幕相同的事情。我有一堆if案例:
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 函数认为 selectedImage 增加了 1 个点 = 1 个像素。所以我最终得到了一张试图适合 iPhone 5 屏幕的非视网膜图片。它看起来像什么?看起来只有我想要的图像的左上象限显示在整个 iPhone 5 屏幕上。看起来没有应用视网膜缩放。

我需要 iPhone 来识别我有一张视网膜友好的 iPhone 5 图片用作背景。我该怎么做呢?

最佳答案

我找到了这个代码 here ,也许它可以帮助您:

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

关于image - iOS Colorwithpattern - 使用自定义 iPhone5 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12847541/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com