gpt4 book ai didi

ios - 如何缩放以适合背景图像 objective-c

转载 作者:行者123 更新时间:2023-12-01 19:53:14 25 4
gpt4 key购买 nike

我正在尝试在没有任何 uiimageview 的情况下设置图像,现在我有了图像,但它水平重复了两次我想缩放并将其修复为屏幕大小你怎么做?

我尝试了一些方法,但没有任何结果

下面是我的代码:

- (void)viewDidLoad {
[super viewDidLoad];
UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@"background_themee.png"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// self.view.backgroundColor = [UIColor colorWithPatternImage:image];
// UIGraphicsBeginImageContext(self.view.frame.size);
// [[UIImage imageNamed:@"background_themee.png"] drawInRect:self.view.bounds];
// UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
// UIGraphicsEndImageContext();
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background_themee"]];
// Do any additional setup after loading the view.
}

提前感谢您的建议!!

最佳答案

colorWithPattern将始终在 View 上重复图像。如果你在 iPhone 中打开,它可能会出现 2 次图像。如果你在 iPad 上运行,可能会显示 4 张图像。所以它不适合背景图像。

您需要的是一个 UIImageView,其约束设置正确,contentMode 设置为 AspectFill。

关于ios - 如何缩放以适合背景图像 objective-c ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44383352/

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