Selecting different storyboards based on device type

后端 未结 4 1545
心在旅途
心在旅途 2020-12-20 13:13

I have a universal app in which I\'m loading my main storyboard manually in application:didFinishLaunchingWithOptions.

I have 2 storyboards for iPhone a

4条回答
  •  死守一世寂寞
    2020-12-20 13:48

    You can name your storyboard like this

    • Main.storyboard (for iPhone)
    • Main_iPad.storyboard (for iPad)

    and select them like this

    - (UIStoryboard *)deviceStoryboardWithName:(NSString *)name bundle:(NSBundle *)bundle {
        if (IS_IPAD) {
            NSString *storyboardIpadName = [NSString stringWithFormat:@"%@_iPad", name];
            NSString *path = [[NSBundle mainBundle] pathForResource:storyboardIpadName ofType:@"storyboardc"];
    
            if (path.length > 0) {
                return [UIStoryboard storyboardWithName:storyboardIpadName bundle:bundle];
            }
        }
    
    
        return [UIStoryboard storyboardWithName:name bundle:bundle];
    }
    

提交回复
热议问题