Reputation: 2687
I'd like to define some parameters for my app which is universal both for iPhone and iPad. I want to define using macro and not to judge them in the run-time. It should be like:
#if TARGET_IPHONE_SIMULATOR
#define SCROLL_SIZE_PORTRAIT CGSizeMake(768, 1024)
#define SCROLL_SIZE_LANDSCAPE CGSizeMake(1024, 768)
#else
#define SCROLL_SIZE_PORTRAIT CGSizeMake(320, 460)
#define SCROLL_SIZE_LANDSCAPE CGSizeMake(460, 320)
#endif
However, this macro can't distinguish iPhone and iPad. Is there any other way to do it? thanks.
Upvotes: 0
Views: 630
Reputation: 6259
If you want to create an universal app, this is definitely not the right way to go as the compiler doesn't know what device the app will run on up front.
Thus even if you use a macro it will have to be evaluated at runtime.
You will have to check for the device at runtime as this is the only time an universal app actually knows (by definition) whether it is executed on an iPhone or iPad.
Upvotes: 0
Reputation: 55563
Use a function:
static inline CGSize scrollSizePortrait()
{
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad ? CGSizeMake(768, 1024) : CGSizeMake(320, 460);
}
static inline CGSize scrollSizeLandscape()
{
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad ? CGSizeMake(1024, 768) : CGSizeMake(460, 320);
}
Upvotes: 1