gpt4 book ai didi

iOS - iPad 背景图像被剪短

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

我有一个 iPad/iPhone 应用程序,iPhone 背景看起来不错,但当我在 iPad 版本中使用相同的图像时,它看起来像是在页面中间被切断了。

这是屏幕截图:

enter image description here

该图像名为buildings.png,我有它的2 个版本,即buildings.png 和适用于iPad 的buildings@2x。

我在后台渲染图像的方式是来自这样的代码:

- (void)viewDidAppear:(BOOL)animated
{
UIImage *image = [UIImage imageNamed:@"building"];
self.view.backgroundColor = [UIColor colorWithPatternImage:image];

解决图像在 iPad View 上被剪切的问题的最佳方法是什么?

谢谢!

最佳答案

我认为 colorWithPatternImage 是您的图像被这样剪切的原因。为什么不创建一个 UIImageView 来包含您的图像,将其添加到您的 View 中并调用 [self.view sendSubviewToBack:yourImageView]

编辑
这是您的代码片段

UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"building"]];
imgView.frame = self.view.bounds; // to set the frame to your view's size
[self.view addSubview:imgView];
[self.view sendSubviewToBack:imgView];

关于iOS - iPad 背景图像被剪短,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12531803/

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