1

Many people are struggling with using different .xib's for different devices.

If "Auto layout" doesn't work for you ( It doesn't for me, it screws up the sizes and images placements ) you will have to manually detect what device the user is using.

I've seen many, many different methods to do this, so I thought I'd just share the easiest one. ( In my opinion )

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Sam Guichelaar
  • 457
  • 2
  • 12
  • yeah but every time people came up with different solutions. Using a BOOL or AppDelegate, and this way it's all together and it's pretty clear what it does :) – Sam Guichelaar Jul 17 '13 at 08:42
  • This isn't a duplicate at all. Different methods, and simpler ones. – Sam Guichelaar Jul 17 '13 at 08:47
  • That doesn't make it not a duplicate. If you have a solution, post it as an answer to the original question. Don't knowingly create duplicates. – dsgriffin Jul 17 '13 at 08:49

1 Answers1

2

So the Answer :

- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle {
if ([[ UIScreen mainScreen ] bounds ].size.height == 568 ) {
    nibName = [NSString stringWithFormat:@"%@_568", nibName];

}

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    nibName = [NSString stringWithFormat:@"%@_iPad", nibName]; {

}

if (self = [super initWithNibName:nibName bundle:nibBundle]) {
}

return self;
}

The first statement checks weather the device you have has the iPhone 5 Screen.

The Second checks weather you're using a iPad.

The third returns the normal xib for the iPhone 4s and prior.

Please note, to make this work you'll have to create 3 different XIB's, all with a different suffix.

ViewController.xib

ViewController_568.xib

ViewController_iPad.xib

Sam Guichelaar
  • 457
  • 2
  • 12