Satyam
Satyam

Reputation: 15894

iPhone - How to use #define in Universal app

I'm creating universal app that runs oniphone and ipad. I'm using #define to create CGRect. And I want to use two different #define - one for iPhone and one for iPad. How can I declare them so that correct one will be picked by universal app..........

I think I've to update little more description to avoid confusion. I've a WPConstants.h file where I'm declaring all the #define as below

#define PUZZLE_TOPVIEW_RECT CGRectMake(0, 0, 480, 100)
#define PUZZLE_MIDDLEVIEW_RECT CGRectMake(0, 100, 480, 100)
#define PUZZLE_BOTTOMVIEW_RECT CGRectMake(0, 200, 480, 100)

The above ones are for iphone. Similarly for iPad I want to have different #define How can I proceed further?

Upvotes: 1

Views: 1870

Answers (2)

Evgen Bodunov
Evgen Bodunov

Reputation: 5906

i used this function to detect iPad, and then write conditions for all different parts of my application.

#ifdef UI_USER_INTERFACE_IDIOM
    #define isPad() (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#else
    #define isPad() NO
#endif

Also you can load different xib files for iPhone/iPad.

Upvotes: 1

Ole Begemann
Ole Begemann

Reputation: 135540

As recommended by Apple, use

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { ... }
else { ... }

to write platform-specific code. With the ternary ?: operator, you could also incorporate this into a #define:

#define MyRect (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? CGRectMake(0,0,1024,768) : CGRectMake(0,0,480,320))

In case you wanted to use conditional compilation to determine which of two #define statements should be included in your code, you can't: a universal app does not contain two separate binaries for iPhone and iPad. It's just one binary so all platform-related decisions have to be made at runtime.

Upvotes: 2

Related Questions