Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separate StoryBoards for iPhone 5 and iPhone 4S [duplicate]

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.

like image 474
iSaalis Avatar asked Oct 05 '12 04:10

iSaalis


People also ask

How do I make multiple storyboards in Xcode?

1. Create storyboards by File -> New -> File -> Select Storyboard -> Next -> Give it a name -> Create. In this demo, we will create 3 storyboards, Shopping, Checkout and Profile.

What is iOS storyboard?

The storyboard is first introduced in iOS 5 to save time building user interfaces for the iOS applications. It is a visual representation of the user interface of an iOS app. It can be defined as the sequence of screens, each of which represents the ViewController and the Views.


1 Answers

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];
    }
like image 178
Bijoy Thangaraj Avatar answered Sep 22 '22 06:09

Bijoy Thangaraj