What i have been doing recently is adding a define statement in any classes i need to check the device. This can also be done in any global header files.
#define IS_IPHONE (!IS_IPAD)
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone)
The bool test is from Detect iphone 5 4" screen.
bool isiPhone5 = CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size,CGSizeMake(640, 1136));
if (isiPhone5) {
// Setup For iPhone 5 Screen Size
UIStoryboard *storyBoard;
storyBoard = [UIStoryboard storyboardWithName:@"MyiPhone5StoryboardName" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
This works beautifully if you are already using storyboards, and only want to change the storyboard from the defaults that your project started with for iPhone 5 devices. If you are starting from scratch with an existing non-Storyboard project you can do it this way.
#define IS_IPHONE (!IS_IPAD)
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone)
bool isiPhone5 = CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size,CGSizeMake(640, 1136));
if (isiPhone5) {
// Load iPhone 5 Storyboard
UIStoryboard *storyBoard;
storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
else if (IS_IPAD) {
// Load IPAD StoryBoard
UIStoryboard *storyBoard;
storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
else {
// Load the iPhone 3.5" storyboard
UIStoryboard *storyBoard;
storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
When i start a project now i design the iPhone 3.5" version in storyboards (If i am using storyboards), then when i am done with that design i go into my project files and find the storyboard file. Since a storyboard file is just an XML layout file, i can take that file and load it in my favorite text editor and change two tags.
Convert iPhone to iPad
- At the top of the file find
targetRuntime="iOS.CocoaTouch
"
- Change to
targetRuntime="iOS.CocoaTouch.iPad"
- Ad the bottom of the file you may find this
<simulatedScreenMetrics key="destination" type="retina4"/>
- Change this to
<simulatedScreenMetrics key="destination"/>
The last item will only appear if the your main storyboard file is setup for the 4" iPhone screen.
What is important here is if your only adding iPhone 5 to an existing project you only need the first check to override the default, and load your special storyboard file. This literally saved me from having to manually layout all objects in code for iPhone 5.