0
votes

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];
1

1 Answers

1
votes

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];