#ifdef to check if device is iPhone 5
height, if-statement, iphone, preprocessor
Solution
Your `IS_IPHONE_5` macro is just fine. You can do things like this:
if (IS_IPHONE_5) {
// do something specific for iPhone 5
}
At compile time this code will be converted to:
if (([UIScreen mainScreen].bounds.size.height == 568.0)) {
}
The problem is your `SCREEN_HEIGHT` macros. The whole `#ifdef` block will be evaluated at compile time. Since you did define `IS_IPHONE_5`, the `SCREEN_HEIGHT` will always be set to 568.
You want a runtime determination of the screen height. You can get this from:
[UIScreen mainScreen].bounds.size.height
Problem
I wrote: ``` #define IS_IPHONE_5 ([UIScreen mainScreen].bounds.size.height == 568.0) #ifdef IS_IPHONE_5 #define SCREEN_HEIGHT 568 #else #define SCREEN_HEIGHT 480 #endif ``` but it always return that device is iPhone 5... What am I doing wrong?