gpt4 book ai didi

iphone - 为 Iphone 3g、Iphone 4s 和 Iphone 5 设置背景图像

转载 作者:行者123 更新时间:2023-11-29 04:14:09 24 4
gpt4 key购买 nike

我想设置 View 的背景图像。我使用三个图像:backgroundimage.png(尺寸320 x 480)、backgroundimage@2x.png(尺寸640 x 960)和backgroundimage-568h@2x.png(尺寸640 x 1136)

适用于 iphone 3g 尺寸。但是当我测试它的视网膜尺寸时,背景图像只是原始图像的一小部分。我认为,我必须以某种方式缩小图像的尺寸,或者为其设置一个框架,但我只是不知道如何做。

感谢您的帮助;)

这就是代码:

self.view.backgroundColor = [UIColor clearColor];
UIImage *backgroundImage = [[UIImage alloc]init];
if ([[UIScreen mainScreen] bounds].size.height == 568) {
backgroundImage = [UIImage imageNamed:@"background-568h@2x"];
}
else{
backgroundImage = [UIImage imageNamed:@"background"];
}
self.view.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];

最佳答案

我的第一个猜测是由于误用了colorWithPatternImage。仅当您有希望平铺的图案图像时才应使用此选项。相反,尝试创建一个 View 大小的 UIImageView,然后将其添加为 self.view 的 subview 。

UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage];
[backgroundImageView setFrame:[[self view] bounds]];
[[self view] addSubview:backgroundImageView];

关于iphone - 为 Iphone 3g、Iphone 4s 和 Iphone 5 设置背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13939181/

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