iPhone 6 a different storyboard?

佐手、 提交于 2019-12-02 04:01:52

No, you should use AutoLayout and write the appropriate constraints and let the system resize your UI for the various sizes.

Best approach is using AutoLayout but if you still have to use different storyboards for different screen size for some reason, following is a working code.

if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
    //iPad
    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_iPhone3_4X" bundle:nil];
        }else if (iOSDeviceScreenSize.height == 568){
            // iPhone 5 - 5s - 4 inch
            storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5_5S" bundle:nil];
        }else if (iOSDeviceScreenSize.height == 667){
            // iPhone 6 4.7 inch
            storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone6" bundle:nil];
        } else if (iOSDeviceScreenSize.height == 736){
            // iPhone 6 Plus 5.5 inch
            storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone6Plus" bundle:nil];
        }

    }
}

To enable native iPhone 6 and iPhone 6 plus screen resolution add launch images

You should be designing the UI for the wAny/hAny "size class" in Interface Builder. Apply auto layout constraints to describe how the views should adapt to different size classes. If you need to, you can override some constraints for specific size classes.

The code you had before that selected the storyboard to load based on device should be removed. It is no longer needed if you use size classes.

There is an excellent WWDC video that introduces the adaptive UI and size classes. I would recommend watching it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!