1

Possible Duplicate:
Is there a specific Xcode compiler flag that gets set when compiling for iPad?

I want to define same macros but different values depending on whether its ipad or iphone. For example, i want define THUMB_WIDTH for iphone is 40 but for ipad is 100. Is this possible? If possible, how to do?

Community
  • 1
  • 1
chancyWu
  • 14,073
  • 11
  • 62
  • 81

1 Answers1

4

Yes, it's possible. First, you have to understand that the macro is just some code that will be replaced in your code at compile time.

I think that you want an universal app (iPhone/iPad), that means that you will have the same code compiled and shared for both platforms. So you cannot use a #if macro to change this value. The logic part have to be in the macro, this way the value is know at execution time and will change depending if you execute on iPhone or iPad.

You can use something like to do it:

#define THUMB_WIDTH (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) ? 40 : 100
Ludovic Landry
  • 11,606
  • 10
  • 48
  • 80