2

I want to define SCREEN_HEIGHT in my app. I used the following code, but it always return 568 for me.Can anyone help me for this?

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

#ifdef IS_IPHONE_5
#define SCREEN_HEIGHT 568
#else
#define SCREEN_HEIGHT 480
#endif

Thanks.

Pankti Patel
  • 296
  • 1
  • 4
  • 14
  • see my edited answer. it is working in my code also my friend... – NiravPatel Sep 27 '13 at 06:56
  • @PanktiPatel Obviously the `#DEFINE` is a compile-time exercise, but the screen height is a run-time determination. So your `#DEFINE` of `SCREEN_HEIGHT` cannot use a constant, but rather must represent some run-time expression (such as something that looks at `[UIScreen mainScreen]` properties). – Rob Sep 27 '13 at 07:00

4 Answers4

2

Write this below line in prifix.pch file...

#define    SCREEN_HEIGHT   [UIScreen mainScreen].bounds.size.height

this will definetly work..i tried it in my code....

Hope it will help my friend...

Happy Coding!!

NiravPatel
  • 3,260
  • 2
  • 21
  • 31
1
 #define height  [UIScreen mainScreen].bounds.size.height
Nirmalsinh Rathod
  • 5,079
  • 4
  • 26
  • 56
0

Try to put #undef SCREEN_HEIGHT before #define SCREEN_HEIGHT

#undef SCREEN_HEIGHT
#ifdef IS_IPHONE_5
#define SCREEN_HEIGHT 568
#else
#define SCREEN_HEIGHT 480
#endif
Ramaraj T
  • 5,184
  • 4
  • 35
  • 68
0

You Can Also Define Screen Height as:

#define ScreenBound       ([[UIScreen mainScreen] bounds])
#define ScreenHeight      (ScreenBound.size.height)
Anuj
  • 820
  • 4
  • 11