Ios 如何缩放以适应背景图像目标c
我试图在没有任何uiimageview的情况下设置图像,现在我有了图像,但它水平重复了两次我想缩放并将其固定到屏幕大小你怎么做 我试过一些方法,但没有成功 下面是我的代码:Ios 如何缩放以适应背景图像目标c,ios,objective-c,xcode,background,Ios,Objective C,Xcode,Background,我试图在没有任何uiimageview的情况下设置图像,现在我有了图像,但它水平重复了两次我想缩放并将其固定到屏幕大小你怎么做 我试过一些方法,但没有成功 下面是我的代码: - (void)viewDidLoad { [super viewDidLoad]; UIGraphicsBeginImageContext(self.view.frame.size); [[UIImage imageNamed:@"background_themee.png"] drawInRect:self.view.b
- (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.
}
提前感谢您的建议
colorWithPattern
将始终在视图上重复图像。如果你在iPhone中打开,它可能会出现2倍的图像。若你们在iPad上运行,可能会出现4张图片。所以对背景图像来说是不好的
您需要的是一个UIImageView,其中正确设置了约束,并将contentMode设置为AspectFill。
您可以根据需要选择缩放填充或纵横比填充/调整simple这行就足够了
self.view.backgroundColor=[UIColor WithPatternImage:[UIImage imageNamed:@“background_themee”]
@GeneCode好的让我试试!!是的,它成功了,谢谢!!如果你认为这是一个有效的问题,你可以投票:)