本文介绍了设置为iPhone 3G,iPhone 4S和iPhone 5的背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想设置视图的背景图像。我用三张图片:backgroundimage.png(尺寸为320×480),[email protected](尺寸640×960)和[email protected](尺寸640×1136)

这为iPhone 3G大小的作品。但是,当我测试它的视网膜大小的背景图像是原始图像的只是一小部分。我想,我必须以某种方式降尺度图像,或者设置一个框架,但我就是不知道怎么办。

感谢所有帮助;)

多数民众赞成在code:

  self.view.backgroundColor = [的UIColor clearColor]
*的UIImage =将backgroundImage [UIImage的ALLOC] INIT]
如果([UIScreen mainScreen]界限] .size.height == 568){
    将backgroundImage = [UIImage的imageNamed:@背景568h @ 2X];
}
其他{
    将backgroundImage = [UIImage的imageNamed:@背景];
}
self.view.backgroundColor = [的UIColor colorWithPatternImage:将backgroundImage];


解决方案

我的第一个猜测是因为 colorWithPatternImage 的滥用。如果你有,你想有瓷砖图案像这应该只被使用。相反,尝试创建一个UIImageView视图的大小,然后将其添加为self.view的子视图。

 的UIImageView * backgroundImageView = [[UIImageView的页头] initWithImage:将backgroundImage];
[backgroundImageView SETFRAME:[自拍]界限]];
[自拍] addSubview:backgroundImageView];

I want to set the background image of a view. I use three images: backgroundimage.png (size 320 x 480), [email protected] (size 640 x 960) and [email protected] (size 640 x 1136)

that works for iphone 3g size. 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. 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 *backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage];
[backgroundImageView setFrame:[[self view] bounds]];
[[self view] addSubview:backgroundImageView];

这篇关于设置为iPhone 3G,iPhone 4S和iPhone 5的背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:00