Bhavin Ramani
Bhavin Ramani

Reputation: 3219

iPad screen size return wrong value

I am making app that runs in all iPhone device 4s,5,5s,6,6+ and iPads..

In this if we choose iPhone 4s simulator it will load 4s storyboard. I have designed separate storyboards for different size of screen.

It works good in all iPhone device but when i choose iPad in simulator option it gives me iPhone 4s screen.

This is code which load different storyboards as per screen size in AppDelegate.

- (UIStoryboard *)grabStoryboard

{
// determine screen size
int screenHeight = [UIScreen mainScreen].bounds.size.height;
NSLog(@"screenHeight:-%d",screenHeight);///here it it gives me 480 in iPad so it goes in case 480.
UIStoryboard *storyboard;


switch (screenHeight)
{
        // iPhone 4s
    case 480:
        storyboard = [UIStoryboard storyboardWithName:@"Main-4s" bundle:nil];
        break;

        // iPhone 5s
    case 568:
        storyboard = [UIStoryboard storyboardWithName:@"Main-5s" bundle:nil];
        break;

        // iPhone 6
    case 667:
        storyboard = [UIStoryboard storyboardWithName:@"Main-6" bundle:nil];
        break;

        // iPhone 6 Plus
    case 736:
        storyboard = [UIStoryboard storyboardWithName:@"Main-6Plus" bundle:nil];
        break;

    default:
        // it's an iPad
        storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        break;
}
 return storyboard;
}

And called this method in didFinishLaunchingWithOptions.

This code is working great in my other app.

Upvotes: 0

Views: 239

Answers (2)

Arben Pnishi
Arben Pnishi

Reputation: 591

Your app is zoomed in your iPad to the resolution of iPhone 4. You need to set the target Devices to Universal.

Upvotes: 1

Adrian
Adrian

Reputation: 16715

There's no need to configure a separate storyboard for each resolution. In Xcode, you can configure layouts for different screen sizes via Interface Builder. At the bottom, you can alter constraints for the various screen sizes.

enter image description here

Here's a brief tutorial that should get you pointed in the right direction.

Upvotes: 0

Related Questions