2

I'm working on a universal iOS app and wanting to use different xib files for iPhone 5. The way it currently works is by automatically selecting the file with the right device modifier (as specified here: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/LoadingResources/Introduction/Introduction.html#//apple_ref/doc/uid/10000051i-CH1-SW2). However there's no mention there of how to handle the iPhone 5. I'm surprised because I'm under the impression they'd prefer developers to create a different/unique experience on the 5 instead of just auto scaling...

Anyone aware of a modifier that works? (eg myxib~iphone5.xib) It would be more convenient than having to handle the device detection and switching myself.

Cheers!

Kaan Dedeoglu
  • 14,765
  • 5
  • 40
  • 41
Kieran Harper
  • 1,098
  • 11
  • 22
  • If you create an iPhone 5 splash image editing the target in Xcode, it will create a separate `Default.png` variant with a suffix/modifier specifically targeting tall iPhones. I have no idea whether the XIB or Storyboard loading respects this. – Jesper Oct 16 '12 at 08:20
  • Yep, tried to use ~568h like the one it uses for that but no luck :( – Kieran Harper Oct 16 '12 at 12:16
  • this may help you http://stackoverflow.com/questions/13275144/how-to-make-xib-compatible-with-both-iphone-5-and-iphone-4-devices/13283851#13283851 – Waseem Shah Jan 28 '13 at 10:55

1 Answers1

4

There's no naming convention unfortunately, but there's a way. This is what I'm using:

I have a global .h file called GlobalConstants that I put all my #define macros in. There I have this:

static BOOL is4InchRetina()
{
    if ((![UIApplication sharedApplication].statusBarHidden && (int)[[UIScreen mainScreen] applicationFrame].size.height == 548) || ([UIApplication sharedApplication].statusBarHidden && (int)[[UIScreen mainScreen] applicationFrame].size.height == 568))
        return YES;

    return NO;
}

then in any of my view controller classes - I override the init method like this:

#import GlobalConstants.h

-(id) init {

if(is4InchRetina()) self = [super initWithNibName:@"myNibName5" bundle:[NSBundle mainBundle]];
else self = [super initWithNibName:@"myNibName" bundle:[NSBundle mainBundle]];

return self
}
Kaan Dedeoglu
  • 14,765
  • 5
  • 40
  • 41
  • 1
    Thanks for this, although it's lame they haven't done it for us. I've settled for something similar to this - a globally accessible method that when given an NSString for an XIB name, returns a new one with the appropriate modifier added manually. So I can just carry on using the ~ipad ~iphone5 scheme for my own purposes – Kieran Harper Oct 16 '12 at 12:18
  • @KieranHarper I hear you on that. Thank you – Kaan Dedeoglu Oct 16 '12 at 13:38