Steaphann
Steaphann

Reputation: 2777

Different layout for iPad and iPhone

I am making an iphone app at the moment. But in the future this app should also be available for iPad. At the moment I am using storyboards, because it's quite easy to make it also available for iPad in this way.

My question is now, some views like a long profile form, you put it inside a scrollview. But you cannot build scrollviews layouts inside a storyboard, so I created them in code. But what should I do if I want this views layout also available for iPad?

Should I rewrite the layout code for iPad and then do some device detection? What is the best practice?

Upvotes: 0

Views: 1488

Answers (3)

Steaphann
Steaphann

Reputation: 2777

The solution was rather simple. First I thought you cannot create scrollviews inside a storyboard. But this is possible! You can find how to do it over here.

So now the solution is that you create another storyboard specifically for iPad!

Upvotes: 0

Nishant B
Nishant B

Reputation: 2907

Below will be useful for you.

#define IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:@"iPhone"] )
#define IS_IPOD   ( [[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"] )
#define IS_IPAD   ( [[[UIDevice currentDevice] model] isEqualToString:@"iPad"] )
#define IS_IPHONE_5_SCREEN [[UIScreen mainScreen] bounds].size.height >= 568.0f && [[UIScreen mainScreen] bounds].size.height < 1024.0f
#define IS_IPHONE_4_SCREEN [[UIScreen mainScreen] bounds].size.height >= 480.0f && [[UIScreen mainScreen] bounds].size.height < 568.0f


if(IS_IPHONE_5_SCREEN)
{
    if(IS_IPHONE)
        NSLog(@"Hey, this is an iPhone 5 screen!");
    else if(IS_IPOD)
        NSLog(@"Hey, this is an iPod 5 screen!");
    else
        NSLog(@"Hey, this is a simulator screen with iPhone 5 screen height!");
}
else if(IS_IPHONE_4_SCREEN)
{
    if(IS_IPHONE)
        NSLog(@"Hey, this is a lower iPhone screen than 5!");
    else if(IS_IPOD)
        NSLog(@"Hey, this is a lower iPod screen than 5!");
    else
        NSLog(@"Hey, this is a lower simulator screen than 5!");
}
else if(IS_IPAD){
    NSLog(@"Hey, this is an iPad screen!");
}
else{
    NSLog(@"Hey, this is an ipad simulator screen!");
}

Cheers!

Upvotes: 0

Yurec Antidipresant
Yurec Antidipresant

Reputation: 107

I think better detect hardware and write different layout code.
You can use Apple's Macro:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
     // Write your layout code for iPad there
}
else
{
     // Write your layout code for iPhone/iPod there
}

Upvotes: 2

Related Questions