本文介绍了如何填充 UIView 的背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 UIView
并且我以这种方式设置了背景图像:
I have an UIView
and I set a background image in this way:
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"sfond-appz.png"]];
我的问题是背景图像没有在视图内居中,但它会重播几次以填充所有视图.有没有办法在 uiview 和 scretch 中居中图像以获得屏幕尺寸?
My problem is that back-image is not centered inside the view, but it's replayed some times to fill all the view. Is there a way to center image inside uiview and scretch to have screen size?
注意:我不能使用 UIImageView
作为背景,因为我有一个 scrollview
.
Note: I can't use UIImageView
for background cause I have a scrollview
.
推荐答案
您需要预先处理图像,以制作居中和拉伸的图像.试试这个:
You need to process the image beforehand, to make a centered and stretched image.Try this:
UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@"image.png"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
这篇关于如何填充 UIView 的背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!