Skip to content

Instantly share code, notes, and snippets.

@vdparikh
Last active August 29, 2015 14:06
Show Gist options
  • Save vdparikh/f23294ce64479b5f5981 to your computer and use it in GitHub Desktop.
Save vdparikh/f23294ce64479b5f5981 to your computer and use it in GitHub Desktop.
iOS - Using a different storyboard for each device type
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Whatever needs to happen before
UIStoryboard *storyboard;
BOOL isIphone = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)? TRUE : FALSE;
if(isIphone) {
//iPhone Family
CGSize deviceScreenSize = [[UIScreen mainScreen] bounds].size;
switch ((int) deviceScreenSize.height) {
case 568:
// iPhone 5 and 5S
storyboard = [UIStoryboard storyboardWithName:@"iPhone5" bundle:nil];
break;
case 750:
// iPhone 6
storyboard = [UIStoryboard storyboardWithName:@"iPhone6" bundle:nil];
break;
case 1080:
// iPhone 6 Plus
storyboard = [UIStoryboard storyboardWithName:@"iPhone6Plus" bundle:nil];
break;
default:
// Older iPhones
storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:nil];
break;
}
}
else {
//iPad Family
storyboard = [UIStoryboard storyboardWithName:@"iPad" bundle:nil];
}
// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [storyboard instantiateInitialViewController];
// Instantiate a UIWindow object and initialize it with the screen size of the iOS device
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Set the initial view controller to be the root view controller of the window object
self.window.rootViewController = initialViewController;
// Set the window object to be the key window and show it
[self.window makeKeyAndVisible];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment