1

Possible Duplicate:
How to detect iPhone 5 (widescreen devices)?

I already have a project which is running properly on iPhone 4 and iPad. Now I want to make that project compatible with iPhone 5 (4 inches).

I have tried using the "Use Auto Layout" but its not working.

My Xcode version is Version 4.5 (4G182).

I have searched over the internet but couldn't find any clue.

If anyone has already resolved this issue then please guide me.

Community
  • 1
  • 1
Omer Waqas Khan
  • 2,423
  • 4
  • 33
  • 62

4 Answers4

4
  1. put a Default Image for iPhone 5 in the project called Default-568h@2x.png. After that the iPhone 5 simulator launched my App fullscreen.

  2. Depending on your Layout you maybe don't need auto layout. I could solve all layout problems with the autoresizing settings in IB. In the end it was simple. I had four kinds of problems:

    • View Controllers that should be fullscreen

enter image description here

  • Elements with fixed distance to the top

enter image description here

  • Elements with fixed distance to the bottom

enter image description here

  • Elements with dynamic distance to top/ bottom that should be scaled with the size of the container

enter image description here

I preffered this way in my existing project. In the next project I will check out the auto layout functionality.

Best, Benjamin

benjamin.ludwig
  • 1,575
  • 18
  • 28
3

I won't recommend creating a separate xib file, This is what I do: 1. Adding 4-inch launch screen - it's a must if you want to use all iPhone 5 screen, There is no other settings for that. 2. If you are using a xib file just open it with interface builder and select every view button etc. and set it to be dynamically placed (using the ruler tab). Pay attention to set windows also to stretch up. 3. If you code your view check that you are dynamically set the places and sizes.

Pay attention that "Auto Layout" isn't backwards compatible so it won't run on versions of iOS before iOS6 (it simply crash)! It is probably useful if you are starting from scratch but for old apps that isn't so good.

Idan
  • 9,880
  • 10
  • 47
  • 76
1

Have you tried adding a new launch image named Default-568h@2x.png to your project?

SteveEdson
  • 2,485
  • 2
  • 28
  • 46
1

One of the possible solutions (probably not the best one) is to load different .xib files depending on screen size. This way you can stil save compatibility with previous iOS versions (<6.0). You can add a category which selects proper .xib file, instead of initWithNibName:

@implementation UIViewController (iPhone5Support)

 -(id) initAutomaticallyWithNibName:(NSString *)nibNameOrNil orIOS6NibName:(NSString*) IOS6NibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
     BOOL isiPhone5 = CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size,CGSizeMake(640, 1136));
     if (isiPhone5==NO) {
         self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
     } else {
         self = [self initWithNibName:IOS6NibNameOrNil bundle:nibBundleOrNil];
         if (self==nil) { NSLog(@" initAutomaticallyWithNibName ERROR - nil for io6 nib name"); }
     }
     return self;
}
@end

Use it like that:

UIViewController *controller = [[UIViewController alloc] initAutomaticallyWithNibName:@"UIViewControllerXibName" orIOS6NibName:@"UIViewControllerXibName_4inch" bundle:nil];

(don't forget to create 2 xib files for the same controller)

krafter
  • 1,425
  • 1
  • 15
  • 28