How to switch to different Storyboard for iPhone 5?

后端 未结 2 747
孤独总比滥情好
孤独总比滥情好 2020-11-28 21:00

Just as an app utilizes different storyboards for iPad and iPhone, I would like my app to use a different storyboard for the iPhone 5. Since there is no option in the Info.

2条回答
  •  悲哀的现实
    2020-11-28 21:55

    This worked for me - slight refinement with wrapping getting the storyboard in a function

    -(UIStoryboard*) getStoryboard {   
        UIStoryboard *storyBoard = nil;
        if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {         
            storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
        }else{
            if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone){
                // The iOS device = iPhone or iPod Touch
                CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
                if (iOSDeviceScreenSize.height == 480){
                    // iPhone 3/4x
                    storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone_4" bundle:nil];
    
                }else if (iOSDeviceScreenSize.height == 568){
                    // iPhone 5 etc
                    storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone_5" bundle:nil];
                }
            }
        }
    
        ASSERT(storyBoard);
        return storyBoard;
    }
    
    UIStoryboard* mainStoryBoard = [self getStoryboard];
        self.initialViewController = [mainStoryBoard instantiateInitialViewController];
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.window.rootViewController = self.initialViewController;
        [self.window makeKeyAndVisible];
    

提交回复
热议问题