Dmitry
Dmitry

Reputation: 14622

How can I create a separate .storyboard for iPhone 3.5 inch on iOS7?

How can I create a separate .storyboard for iPhone 3.5 inch on iOS7? I've already added it to the project but don't know how to activate different .storyboard file for the application.

P.S. There is no code with initWithNibName on my project.

Upvotes: 1

Views: 755

Answers (2)

Gavin
Gavin

Reputation: 8200

By default all iPhone screen sizes will share the same storyboard. You can use either auto layout or the autoresizing (struts and springs) to make adjustments to account for the differences in screen size. This is the preferred way because then you don't have to update two different storyboards when you make UI changes. You can also make adjustments in code to account for the different screen sizes, which is sometimes necessary for more complex changes.

If you must use a separate storyboard, then you will need to go into your project target and remove the storyboard from where it says "Main Interface". Then go in to your app delegate. In the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method, you'll need to add code similar to the following:

self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *viewController = [storyboard instantiateInitialViewController];
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];

You can examine the height of the screen by looking at UIScreen.mainScreen.bounds to choose a different storyboard to use in the line where it gets the storyboard.

As I said, though, I think it is a much better idea to use the same storyboard and use things like auto layout to make the screen adjustments. It'll be much easier to maintain, look cleaner, and probably be less buggy.

Upvotes: 4

lehn0058
lehn0058

Reputation: 20237

I wouldn't recommend doing this unless the views are actually different (not just different in size). BUT, it is possible if you check the window size in your app delegate and then manually load the storyboard ask explained here:

Using Multiple Storyboards in iOS

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MyStoryboardIdentifier" bundle:nil];
UIViewController* myStoryBoardInitialViewController = [storyboard instantiateInitialViewController];

[self.navigationController pushViewController:myStoryBoardInitialViewController animated:YES];

Upvotes: 1

Related Questions