3

The previous posting on here about migrating to iPhone 5 only mention adding a new sized launch image* and maybe using AutoLayout if need be.

But I have a few xibs where there is a background image which fills up the whole of the screen (maybe minue the navigation and tab bar, depending upon the view). To support iPhone 5 I will now need different images for the different screen size, how is this dealt with in the xib or elsewhere?

(*incidentally what do you do if the app doesn't use a launch image?)

Ravi
  • 7,929
  • 6
  • 38
  • 48
Gruntcakes
  • 37,738
  • 44
  • 184
  • 378

1 Answers1

3

Here's a link that will actually help you. Save the launch image, iOS doesn't automatically pick the right image if you put in a "-568h@2x.png" at the end of the file name. There are a couple of helper methods mentioned in the above link that will make your job easy.

I have adopted the code in the links I mentioned above and here's the helper function for Obj-C:

-(BOOL) IsTall
{
    return ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) && ([[UIScreen mainScreen] bounds].size.height * [[UIScreen mainScreen] scale] >= 1136);
}

A little category-writing would help too.

@interface NSString (Special)
-(NSString*)correctImageNameForiPhone5
@end

@implementation NSString (Special)
-(NSString*)correctImageNameForiPhone5
{
    if([self isTall])
            return -imageNameAppendedWith_-568h@2x.png_-; //Do the correct NSString magic here
    else
            return -originalImageName-;
}
@end

Finally, when you are accessing the UIImage object:

NSString *filename = @"backgroundImage.png";
UIImage *img = [UIImage imageNamed:[filename correctImageNameForiPhone5]];

The assumption here is that you would have all your iPhone5-specific image file names ending with "-568h@2x". This code sample is definitely not gonna work if you just drop it into your project, but you get the idea. It needs some NSString fixes.

Ravi
  • 7,929
  • 6
  • 38
  • 48
  • 1
    This is doing it programatically, so xibs with backgrounds can no longer be used? – Gruntcakes Oct 05 '12 at 21:47
  • If iOS can't handle automatic resizing based on naming convention, I don't see any other option. Although I'd love to know if there's a way out!! – Ravi Oct 06 '12 at 04:26
  • There is another way to handle taller images programatically. https://github.com/gaj/imageNamed568 – UIBuilder Oct 13 '12 at 17:15