Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xcode 4.5 how to pick storyboards at launch

Trying to make my app work with both iPhone 5 and iPhone 4/4s. I tried the "AutoLayout" but does not seem to work for my app also read that it is not supported in iOS 5. AutoLayout specifically fails on a view controller that has an UIScrollview and a UIPicker that is re-sized in code. Having two Storyboards one for 4 inch and one for 3.5 inch seems the way to go.

The two Storyboard aproch seem to be the solution for me. So this leaves me with two questions;

  1. Where should the code to detect then if it is a 4/4s/5 go? I would assume in the appDelegate.m in the didFinishLaunchingWithOptions method

  2. How do I change the "Main Storyboard"?

like image 550
Xaphann Avatar asked Sep 21 '12 19:09

Xaphann


People also ask

Should I use storyboard in Xcode?

Another benefit to using Storyboards (over creating views programmatically) is that you get to see what your view will look like at runtime without having to run your app. You can quickly make a change in Interface Builder and immediately see what it'll look like – without waiting for Xcode to compile and run.

Can you mix SwiftUI and storyboard?

The answer is YES! Here we will be discussing a simple way to use SwiftUI into our existing project, which already consists of a storyboard.


2 Answers

This is a great question.

What you need to do is,

  1. Select your current 4/4s storyboard, go to File, duplicate, then give it an iPhone 5 specific name. Make sure that Target and your app name is checked.

  2. Next you have to select the scenes in your storyboard and in the Attributes Inspector change the size to Retina 4 Full Screen. This allows you to rearrange everything for this display.

  3. Finally in application didFinishLaunchingWithOptions paste the following code with the storyboard name you gave for your 4 inch storyboard.

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){     UIStoryboard *storyBoard;      CGSize result = [[UIScreen mainScreen] bounds].size;     CGFloat scale = [UIScreen mainScreen].scale;     result = CGSizeMake(result.width * scale, result.height * scale);      if(result.height == 1136){         storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone_5" bundle:nil];         UIViewController *initViewController = [storyBoard instantiateInitialViewController];         [self.window setRootViewController:initViewController];     } }  return YES; } 

If anyone don't get how to do step 1, do as below.

  1. Go to Project directory and copy paste the MainStoryboard.storyboard and rename new storyboard to say MainStoryboard5.storyboard.

  2. Add this new storyboard MainStoryboard5.storyboard in project (in Xcode) by right clicking Project and clicking Add Files to ....

  3. Now we have two storyboards in xcode.

Tip

You may have to use 'Product > Clean' for this to work after you have done all the above.

like image 84
fields.cage Avatar answered Nov 05 '22 03:11

fields.cage


Currently the only way is to check if you're using the iPhone 5 is the [UIScreen mainScreen] bounds] and [[UIScreen mainScreen] scale].

BOOL isIphone5 = (([[UIDevice currentDevice] userInterfaceIdiom] 
== UIUserInterfaceIdiomPhone) && (([UIScreen mainScreen].bounds.size.height * 
[[UIScreen mainScreen] scale]) >= 1136));

This only works if you have at least added a [email protected] launch image to your application. Else this will always return false. (Because the screen will be letterboxed if you don't have the launch image)

To set the storyboard to your iPhone 5 version you might want to take a look at this question

like image 30
Leon Lucardie Avatar answered Nov 05 '22 03:11

Leon Lucardie