[英]set background images for Iphone 3g, Iphone 4s and Iphone 5
I want to set the background image of a view. 我想设置视图的背景图像。 I use three images: backgroundimage.png (size 320 x 480), backgroundimage@2x.png (size 640 x 960) and backgroundimage-568h@2x.png (size 640 x 1136)
我使用了三个图像:backgroundimage.png(尺寸为320 x 480),backgroundimage @ 2x.png(尺寸为640 x 960)和backgroundimage-568h@2x.png(尺寸为640 x 1136)
that works for iphone 3g size. 适用于iPhone 3G尺寸。 But when I test it for retina size the background image is just a small part of the original image.
但是,当我测试其视网膜大小时,背景图像只是原始图像的一小部分。 I think, that I have to downscale the image somehow, or set a frame for it, but I just don't know how.
我认为我必须以某种方式缩小图像或为其设置框架,但我只是不知道如何。
Thanks for any help ;) 谢谢你的帮助 ;)
thats the code: 多数民众赞成在代码:
self.view.backgroundColor = [UIColor clearColor];
UIImage *backgroundImage = [[UIImage alloc]init];
if ([[UIScreen mainScreen] bounds].size.height == 568) {
backgroundImage = [UIImage imageNamed:@"background-568h@2x"];
}
else{
backgroundImage = [UIImage imageNamed:@"background"];
}
self.view.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];
My first guess is because of the misuse of colorWithPatternImage
. 我的第一个猜测是由于滥用
colorWithPatternImage
。 This should only be used if you have a pattern image that you wish to have tiled. 仅当您有想要平铺的图案图像时,才应使用此选项。 Instead try creating a UIImageView the size of the view, and then adding it as a subview of self.view.
而是尝试创建一个具有视图大小的UIImageView,然后将其添加为self.view的子视图。
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage];
[backgroundImageView setFrame:[[self view] bounds]];
[[self view] addSubview:backgroundImageView];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.