2017-06-06 57 views
1

我想设置图像没有任何uiimageview,现在我有图像,但它是水平重复两次我想缩放和修复它到屏幕大小你如何做到这一点??如何缩放以适合背景图像的目标c

我已经尝试了一些方法,但没有制定出

下面

是我的代码:

- (void)viewDidLoad { 
[super viewDidLoad]; 
UIGraphicsBeginImageContext(self.view.frame.size); 
[[UIImage imageNamed:@"background_themee.png"] drawInRect:self.view.bounds]; 
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
// self.view.backgroundColor = [UIColor colorWithPatternImage:image]; 
// UIGraphicsBeginImageContext(self.view.frame.size); 
// [[UIImage imageNamed:@"background_themee.png"] drawInRect:self.view.bounds]; 
// UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
// UIGraphicsEndImageContext(); 
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background_themee"]]; 
// Do any additional setup after loading the view. 
} 

在此先感谢您的建议!

+0

简单的这条线就足够了'self.view.backgroundColor =的UIColor colorWithPatternImage:[UIImage的imageNamed:@“background_themee “]];' –

+0

@GeneCode ok让我试试吧! – Akshay

回答

1

colorWithPattern将始终在视图上重复图像。如果您在iPhone中打开,它可能会出现2倍的图像。如果你在iPad上运行,可能会显示4张图片。所以它对背景图像不好。

你需要的是一个UIImageView,其中包含正确设置的约束和contentMode设置为AspectFill。

+1

是的,它工作谢谢你!你可以投票,如果你认为这是一个有效的问题:) – Akshay

1

enter image description here

可以选择规模填写或填写方面/ FIT根据您的需要