Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 4.5 background image iPhone 4, 4s, 5

I have in my viewController.m written the background code:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"image.png"]];

And I have the correct names of the different pictures:

image.png for non-retina display (320x480)

[email protected] for retina display (640x960)

[email protected] for iPhone 5 (640x1136)

But when I run it in the simulator it does not take the [email protected] for iPhone 5 screen it only takes the image@2x for 4s screen and scale it to fit the screen... I dont know if there is any coding to use the image-568h@2x for iPhone 5 screen?

Im using Xcode 4.5

like image 474
Peter Avatar asked Oct 25 '12 14:10

Peter


1 Answers

iPhone 5 is retina, just like iPhone 4 and 4S, and the @2x-image will be used automatically for all these devices. It's only the startup-image that is called "-568h@2x" for iPhone 5. You need to write some code to use a different image, something like this would work:

NSString *filename = @"image.png";
CGRect screenRect = [[UIScreen mainScreen] bounds];
if (screenRect.size.height == 568.0f)
    filename = [filename stringByReplacingOccurrencesOfString:@".png" withString:@"-568h.png"];

imageView.image = [UIImage imageNamed:filename];
like image 181
TheQ Avatar answered Oct 05 '22 22:10

TheQ