Separate StoryBoards for iPhone 5 and iPhone 4S [duplicate]
Asked Answered
R

1

15

Possible Duplicate:
How to develop or migrate apps for iPhone 5 screen resolution?

How can I load separate storyboards for iPhone 5 and iPhone 4S/4/3G??

I wana do this because screen size is different for iPhone 5.

Rocket answered 5/10, 2012 at 4:5 Comment(4)
A little search would have uncovered a lot of information. Try https://mcmap.net/q/73953/-how-to-develop-or-migrate-apps-for-iphone-5-screen-resolution.Salpingitis
Actually, I have seen those solutions, letterbox mode or redesign using code based on screen size. But I want to design a separate StoryBoards for 1136 and 960 height screens. We can have separate storyboards for iPad and iPhone using pList. But I want to know, is it possible to load different storyboards for iPhone 5 and iPhone 4S.... ???Rocket
And what happens when the next iPhone is 1280x1024? Or a similarly sized mini iPad appears? My point is that you need to get out of the habit of designing for every form factor and start using the new layout constraint tools. Imagine if you have to redesign a PC app for every possible screen resolution...Salpingitis
rsswtmr your argument is right.... but I am developing for iOS 5.1 as my deployment target... So I can't use the Layout constraint tools for iOS 6 SDK... I know a separate storyboard approach won't be the best one, but still would like to know if it is possible??Rocket
R
32

In your app delegate, you will need to add/replace the following code in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_4inch" bundle:nil];
} else {
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
}

where ViewController_4inch is the name of the nib file that is designed for iPhone 5 screen

UPDATE (STORYBOARD-SPECIFIC ANSWER):

To load different storyboards on launch, use this code:

    CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;

    if (iOSDeviceScreenSize.height == 480)
    {   
        // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
        UIStoryboard *iPhone35Storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone35" bundle:nil];

        // Instantiate the initial view controller object from the storyboard
        UIViewController *initialViewController = [iPhone35Storyboard 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];
    }

    if (iOSDeviceScreenSize.height == 568)
    {   // iPhone 5 and iPod Touch 5th generation: 4 inch screen
        // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
        UIStoryboard *iPhone4Storyboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone4" bundle:nil];

        UIViewController *initialViewController = [iPhone4Storyboard instantiateInitialViewController];
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.window.rootViewController  = initialViewController;
        [self.window makeKeyAndVisible];
    }
Romanist answered 5/10, 2012 at 6:57 Comment(6)
it doesnt answer my question.... How can same app load separate storyboards for iPhone 5 and iPhone 4S/4/3G ??Rocket
shouldn't the iphone 4(s) screensize.height be set == 968?Gav
@Chris No. It shouldn't be.Romanist
@BijoyThangaraj wikipedia says the screen height of the iPhone 5 is 1136, the screen height of the iPhone 4 is 968, and the iPhone 3(G)(S) is 480 if I'm not mistaken.Gav
@Chris The actual screen height is 960 pixels but [[UIScreen mainScreen] bounds].size.height returns 480 in iPhone 4S with a scale factor of 2.Romanist
Don't be confused with pixels and pointsShush

© 2022 - 2024 — McMap. All rights reserved.