0

Hello everyone i have these defined in my .pch

#define HIDE_TABBAR
#define SHOW_TABBAR

#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

And

#if IS_IPHONE_5
HIDE_TABBAR=568 
#else
HIDE_TABBAR=480 
#endif

#if IS_IPHONE_5
SHOW_TABBAR=519
#else
SHOW_TABBAR=431
#endif

Basically what i want to do is to check if screen is iphone 5 , and depending screen size set the define variables and use it in .m code. Can you tell me how i can achieve this?

veereev
  • 2,650
  • 4
  • 27
  • 40

2 Answers2

2

Do like this

   if(IS_IPHONE_5)
    {
      // for iphone 5
    }
    else
    {
        // for non iphone 5
    }

EDIT: (wrt: avoid using if/else in my code) use Ternary operation

Muruganandham K
  • 5,271
  • 5
  • 34
  • 62
1

Like this:

const int HIDE_TABBAR = IS_IPHONE_5 ? 568 : 480;
const int SHOW_TABBAR = IS_IPHONE_5 ? 519 : 431;

or even:

const int HIDE_TABBAR = IS_IPHONE_5 ? 568 : 480;
const int SHOW_TABBAR = HIDE_TABBAR - 49;

If you really have to use macros for this (which is bad programming, but hey, it's your app):

#define HIDE_TABBAR (IS_IPHONE_5 ? 568 : 480)
#define SHOW_TABBAR (HIDE_TABBAR - 49)
Paul R
  • 208,748
  • 37
  • 389
  • 560