6

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)

image@2x.png for retina display (640x960)

image-568h@2x.png for iPhone 5 (640x1136)

But when I run it in the simulator it does not take the image-568h@2x.png 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

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Peter
  • 1,848
  • 4
  • 26
  • 44
  • which version of Xcoe you are using? – Jigar Pandya Oct 25 '12 at 14:05
  • Original question: http://stackoverflow.com/questions/13055007/xcode-4-5-different-iphone-backgroud-on-iphone-4s-and-5 Instead of recreating the questions, consider providing more information in the original one, gaining a little reputation and starting a bounty. – A-Live Oct 25 '12 at 14:06
  • version 4.5, what does it mean to starting a bounty? – Peter Oct 25 '12 at 14:07
  • it means offer more points to someone who answer this question... if you offer 50 bounty that will be added to someone whome you accept ansewr and debited from you account... – Jigar Pandya Oct 25 '12 at 14:08

3 Answers3

13

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];
TheQ
  • 6,858
  • 4
  • 35
  • 55
  • is the "imageView" here @synthesize? or..? – Peter Oct 25 '12 at 14:29
  • 1
    Check out this sample-project: https://www.dropbox.com/s/gcc081dy0frs20z/RetinaImageTest.zip. If you run it in the different simulator devices, you will see three different (extremely ugly) images :) They should of course be different resolutions, but it's a proof of concept. – TheQ Oct 25 '12 at 14:35
3

if you are trying to use [UIImage imageNamed:@"image.png"] and expect image-568h@2x.png to be picked automatically from the bundle for iPhone 5, it will not work. Automatic picking works only for iPhone 4 and 4S.

Only the Default image named as Default-568h@2x.png will be picked automatically in iPhone 5.

for normal images, if you have 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
}
Roshit
  • 1,589
  • 1
  • 15
  • 37
2

I believe it is incorrect 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 at app launch on a 4" display device, as well as the "flag" to enable 4" display support in the SDK. For example, once you include this specific file, your table views will fill the screen.

I have not read anything to suggest that you can simply provide any image with the -568h@2x file name component and have it be used automagically. You'll have to do that yourself based on the screen size, e.g. [UIScreen mainScreen].bounds.size.height.

Mark Granoff
  • 16,878
  • 2
  • 59
  • 61