我有一个UIView
,我用这种方式设置背景图像:
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"sfond-appz.png"]];
我的问题是,背面图像没有在视图中居中,但它会被重放几次以填充所有视图.有没有办法将uiview和scretch中的图像居中以获得屏幕大小?
注意:我不能用UIImageView
作为背景,因为我有一个scrollview
.
我有一个UIView
,我用这种方式设置背景图像:
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"sfond-appz.png"]];
我的问题是,背面图像没有在视图中居中,但它会被重放几次以填充所有视图.有没有办法将uiview和scretch中的图像居中以获得屏幕大小?
注意:我不能用UIImageView
作为背景,因为我有一个scrollview
.
你需要事先处理图像,使图像居中并拉伸.
UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@"image.png"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.backgroundColor = [UIColor colorWithPatternImage:image];