gpt4 book ai didi

iphone - 如何填充 UIView 的背景图像

转载 作者:IT老高 更新时间:2023-10-28 11:26:29 25 4
gpt4 key购买 nike

我有一个 UIView 并以这种方式设置背景图像:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"sfond-appz.png"]];

我的问题是背景图像不在 View 内居中,但它会重放几次以填充所有 View 。有没有办法让 uiview 中的图像居中并显示屏幕尺寸?

注意:我不能使用 UIImageView 作为背景,因为我有一个 scrollview

最佳答案

您需要预先处理图像,以制作居中和拉伸(stretch)的图像。试试这个:

UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@"image.png"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

self.view.backgroundColor = [UIColor colorWithPatternImage:image];

关于iphone - 如何填充 UIView 的背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8077740/

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