如何填补的UIView的背景图片 [英] How to fill background image of an UIView

查看:239
本文介绍了如何填补的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 背景,因为我有一个滚动视图

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的背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆