iPhone 3.5尺寸适用于单独的故事板?

时间:2016-04-12 01:25:28

标签: objective-c iphone storyboard

- (UIStoryboard *)grabStoryboard {
    // determine screen size
    int screenHeight = [UIScreen mainScreen].bounds.size.height;
    UIStoryboard *storyboard;

    switch (screenHeight) {
        // iPhone 5
        case 320:
            storyboard = [UIStoryboard storyboardWithName:@"iPhone4Storyboard" bundle:nil]
                ;
            break;
        // iPhone 6
        case 375:
            storyboard = [UIStoryboard storyboardWithName:@"iPhone6Storyboard" bundle:nil];
            break;
        // iPhone 6 Plus
        case 414:
            storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            break;
        default:
            // It's an iPad
            storyboard = [UIStoryboard storyboardWithName:@"MainiPad" bundle:nil];
            break;
    }

    return storyboard;
}

我使用该代码使我的应用程序在iPhone 5,6,6 plus和iPad上运行。现在,我想让它支持iPhone 4尺寸,或者更确切地说是支持3.5屏幕。我输入了什么代码?另外,Objective-C代码,不是很快。

Autolayout非常糟糕,所以不要给出答案。有人可以说出我必须使用哪些代码吗?

1 个答案:

答案 0 :(得分:0)

试试这个

if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ){
            CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
            CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;

            if( screenHeight < screenWidth ){
                screenHeight = screenWidth;
            }

     if( screenHeight > 480 && screenHeight < 667 ){
                    //NSLog(@"iPhone 5/5s");

                } else if ( screenHeight > 480 && screenHeight < 736 ){
                    //NSLog(@"iPhone 6");

                } else if ( screenHeight > 480 ){
                    //NSLog(@"iPhone 6 Plus");

                } else {
                    // NSLog(@"iPhone 4/4s");

                }