0

Ok, so with xcode you can have different screen sizes for the iPhone 5 and the iPhone 4, when I try to place things on the Storyboard file they always muck up, like I place everything one way for the iPhone 5 and then it gets cut off on the iPhone 4. Is there a way of having two different versions of the storyboard maybe, so I could position the objects for each screen size differently?

Condrum
  • 63
  • 2
  • 11
  • possible duplicate of [How to develop or migrate apps for iPhone 5 screen resolution?](http://stackoverflow.com/questions/12395200/how-to-develop-or-migrate-apps-for-iphone-5-screen-resolution) – jscs Dec 01 '13 at 23:43
  • 1
    @JoshCaswell I don't want to change my screen resolution from a previous version, I want two seperate storyboards for the screen size and positioning of objects in the Storyboard file, One for iPhone 4 or whatever uses the smaller screen and one for the iPhone 5 or whatever uses the same/similar size screen. – Condrum Dec 02 '13 at 00:09
  • That's covered there. See also [Separate storyboards for iPhone 5 and iPhone 4s](http://stackoverflow.com/q/12739313) – jscs Dec 02 '13 at 00:11
  • Auto Layout is your friend. – uchuugaka Dec 02 '13 at 16:17

1 Answers1

0

You could do this manually in the code by choosing your storyboard based on screen size. However, I don't think that there is a way to do it automatically, since the app's info.plist only has Main storyboard file base name, Main storyboard file base name (iPad), and Main storyboard file base name (iPhone).

To do it manually, you'll want to load your first view controller in your app delegate like this:

//AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
    if ([UIScreen mainScreen].bounds.size.height == 568.0) {
        //device is an iPhone 5 or 5S
        storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard568Height" bundle:[NSBundle mainBundle]];
    }
    self.window.rootViewController = [storyboard instantiateInitialViewController];
    [self.window makeKeyAndVisible];
}

Once you've loaded your first view controller this way, you should be able to just use the segues in that storyboard to avoid this logic again. If you need to load a view controller manually you can just access the self.storyboard property of the current UIViewController to make sure you are accessing the correct storyboard without checking the screen height.

Jumhyn
  • 6,687
  • 9
  • 48
  • 76
  • Sorry, but how exactly do I do this? Or perhaps where do I change the code to this? – Condrum Dec 02 '13 at 00:06
  • Actually, the best way to do this might be to set it up in the app delegate. I've updated my answer accordingly. – Jumhyn Dec 02 '13 at 00:27
  • Its not working for me, I created a second Storyboard so they are both called `Main.storyboard` and `Main2.storyboard` but it doesnt work so my code looks like this `UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]]; if ([UIScreen mainScreen].bounds.size.height == 568.0) { //device is an iPhone 5 or 5S storyboard = [UIStoryboard storyboardWithName:@"Main2" bundle:[NSBundle mainBundle]]; } self.window.rootViewController = [storyboard instantiateInitialViewController]; [self.window makeKeyAndVisible]; } ` – Condrum Dec 02 '13 at 01:04
  • In my `AppDelegate.m` file. But when I run that code through the simulator or my iPhone 4 it always automatically loads the main.storyboard file. – Condrum Dec 02 '13 at 01:13
  • Check if the `if` statement is getting executed, and then do a check on the screen bounds to see what they are. – Jumhyn Dec 02 '13 at 01:18
  • How do I do that? I tried adding NSLogs in there but they didnt execute at all. – Condrum Dec 02 '13 at 01:29
  • Set a breakpoint at the line of the if statement, and use `lldb` to check the current properties. – Jumhyn Dec 02 '13 at 02:08
  • You should be able to find info online about debugging with Xcode. – Jumhyn Dec 02 '13 at 03:19