有谁能帮我理解我如何将背景图像对象应用到UIView?
我创建了一个背景图像,它是背景的模糊版本,我想将它应用为前景中uiView的背景,理想情况下会掩盖背景图像。
到目前为止,我有以下代码 -
_blurImage = [source stackBlur:50];
[_HPBlurView.backgroundColor = [UIColor colorWithPatternImage:[_blurImage]]];
我想将图像对象(_blurImage)应用为_hpBlurView的背景图像,但我正在努力让它工作!
答案 0 :(得分:1)
创建图像并添加到背景中。:
UIImage *image = [UIImage imageNamed:@"youimage"];
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
就是这样。
答案 1 :(得分:1)
乍一看,你使用了太多括号。这是您的代码的工作版本:
_burImage = [source stackBlur:50];
_HPBlurImage.backgroundColor = [UIColor colorWithPatternImage:_blurImage];
我无法看到stackBlur:50
返回的内容。所以从头开始。 colorWithPatternImag
将UIImage
作为参数。首先,将图片,任何图片添加到您的应用程序中。让我们假设图像被称为image.png
。这是一种方法:
UIImage *image = [UIImage imageNamed:@"image.png"];
_HPBlurView.backgroundColor = [UIColor colorWithPatternImage:image];
这应该有助于你前进。
答案 2 :(得分:1)
为了确保所有内容都正确调整大小,无论旋转,设备大小和iOS版本,我只需设置一个UIImageView
//Create UIImageView
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.frame]; //or in your case you should use your _blurView
backgroundImageView.image = [UIImage imageNamed:@"image.png"];
//set it as a subview
[self.view addSubview:backgoundImageView]; //in your case, again, use _blurView
//just in case
[self.view sendSubviewToBack:backgroundImageView];