Xcode 4.5 background image iPhone 4, 4s, 5

I have background code written in my View of Controller.m:

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

And I have the correct names for different images:

 image.png for non-retina display (320x480) image@2x.png for retina display (640x960) image-568h@2x.png for iPhone 5 (640x1136) 

But when I run it in the simulator, on the iPhone 5 screen it does not accept the image 568h@2x.png , it only accepts the @ 2x image for the 4s screen and scales it to fit the screen ... I don’t know if there is any encoding for use image-568h @ 2x for iPhone 5 screen?

Im using Xcode 4.5

+6
source share
3 answers

The iPhone 5 is a retina, just like the iPhone 4 and 4S, and the @ 2x image will be used automatically for all of these devices. This is just a startup image called β€œ-568h @ 2x” for iPhone 5. You need to write code to use another image, something like this will 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]; 
+13
source

If you try to use [UIImage imageNamed:@"image.png"] and expect image-568h@2x.png be automatically selected from the iPhone 5 bundle, this will not work. Auto Build only works for iPhone 4 and 4S.

Only the default image, named as Default-568h@2x.png , will be automatically selected on iPhone 5.

for regular images, if you have a separate image for iPhone 5, try using this code

 CGRect screenBounds = [[UIScreen mainScreen] bounds]; if (screenBounds.size.height == 568) { // code for 4-inch screen } else { // code for 3.5-inch screen } 
+3
source

I believe it is wrong to assume that you can apply the -568h@2x trick to all image files. I think it only works for Default-568h@2x.png . This is the file that iOS looks for when launching the application on a 4-inch display device, as well as a β€œflag” to enable β€œ4” support in the SDK. For example, after including this particular file, your tables will fill the screen.

I have not read anything to suggest that you can simply provide any image with the file name component -568h@2x and use it automatically. You will need to do this yourself based on screen size, for example. [UIScreen mainScreen].bounds.size.height .

+2
source

All Articles