6

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

I am creating an app using Xcode. I have noticed that with xcode 4.5, your storyboards can adapt to iphone 5 screen size. If I create two separate storyboards with the different screen sizes, but link the controllers to the same .h file, how can I tell the program which storyboard to load depending on the device?

eg: for the ipad, when I run, it picks the right storyboard automatically

Community
  • 1
  • 1
Alessandro
  • 4,000
  • 12
  • 63
  • 131

2 Answers2

48

The currently marked answer did not work for me so I created the method below to check if the current device has an 4 inch display.

- (BOOL)hasFourInchDisplay {
    return ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && [UIScreen mainScreen].bounds.size.height == 568.0);
}

Since that is the known height for the 4 inch display on the iPhone it is a good indicator.

Brennan
  • 11,546
  • 16
  • 64
  • 86
  • 2
    I have since stopped checking for the exact screen height and I have learned to flex the UI from the NIB and it works surprisingly well. I also had to resize images and created this solution. http://stackoverflow.com/questions/12648129/uiimageview-programmilly-manage-for-iphone5-and-iphone4/12774544#12774544 – Brennan Oct 08 '12 at 15:09
  • This answer works well for me. My use case involves changing the height of a scroll view. My dependency is related to a group of text fields (form) in the scroll view and the need for the scroll view to be full screen height when keyboard is not present but different heights for 3.5", 4" and iPad. – hippeelee Feb 14 '13 at 02:03
5

Add this code in your initializtion:

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
     if([UIScreen mainScreen].bounds.size.height == 568.0)){
             //move to your iphone5 storyboard
             [UIStoryboard storyboardWithName:(NSString *) bundle (NSBundle *)];
  }
     else{
             //move to your iphone4s storyboard
             [UIStoryboard storyboardWithName:(NSString *) bundle (NSBundle *)];
  }
}

.h (header file) holds the initialization. After the put brackets {} and inside the brackets initialize your data structures such as IBOutlet, int, string. Outside place your methods such as an IBAction or void.

SkylerHill-Sky
  • 2,106
  • 2
  • 17
  • 33