Conditional Compilation between ipad and iphone

2019-04-15 05:05发布

As well as runtime checks for deciding on code paths for an iphone/ipad app, is there a conditional compilation flag anywhere that can be used to reduce code size? Apple seems to suggest it in their development notes, but I can't find anything anywhere.

How do others do this?

Thanks

1条回答
时光不老,我们不散
2楼-- · 2019-04-15 06:09

You can use the following function and check for if isPad then do code for iPad else code for iPhone

- (BOOL) isPad{ 
#ifdef UI_USER_INTERFACE_IDIOM
    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
#else
    return NO;
#endif
}

if([self isPad])
{
//do code for iPad
}
else
{
//do code for iphone
}
查看更多
登录 后发表回答