为iphone 3g,iphone 4s和iphone 5设置背景图片
我想设置一个视图的背景图像。 我使用三个图像:backgroundimage.png(尺寸320 x 480),backgroundimage@2x.png(尺寸640 x 960)和backgroundimage-568h@2x.png(尺寸640 x 1136)
适用于iPhone 3G的大小。 但是当我testing视网膜大小时,背景图像只是原始图像的一小部分。 我认为,我不得不以某种方式缩小图像,或者为它设置一个框架,但我不知道如何。
谢谢你的帮助 ;)
这是代码:
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];
我的第一个猜测是因为colorWithPatternImage
的滥用。 这应该只用于如果你有一个模式图像,你想平铺。 请尝试创build视图大小的UIImageView,然后将其添加为self.view的子视图。
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage]; [backgroundImageView setFrame:[[self view] bounds]]; [[self view] addSubview:backgroundImageView];