Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preprocessor-IF doesn't work

I'm trying to check with Preprocessor-Ifs if the Device is an iPad. If it is an iPad, I want to define something Devicespecific, but for some reason I can't check in an PP-IF if a PP-Constant is true.

Maybe you got an idea?

#ifdef UI_USER_INTERFACE_IDIOM

    #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

#else

    #define IS_IPAD false

#endif



#if IS_IPAD

    #define WIDTH 768
    #define HEIGHT 1024

#else

    #define WIDTH 320
    #define HEIGHT 480

#endif
like image 340
Kevin Glier Avatar asked Feb 27 '26 05:02

Kevin Glier


2 Answers

Preprocessor rules are, (surprise, surprise) processed prior to building the app. Since it's an universal app, it doesn't yet know if it's running on an iPad or an iPhone.

Use this:

#ifdef UI_USER_INTERFACE_IDIOM
    #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#else
    #define IS_IPAD false
#endif

#define WIDTH (IS_IPAD ? 768 : 320)
#define HEIGHT (IS_IPAD ? 1024 : 480)
like image 122
cutsoy Avatar answered Mar 01 '26 17:03

cutsoy


This is my approach: you can use this in the header file

#define _IPAD ((__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200) && (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad))
#define GUI_TITLE_LABEL_WIDTH    (_IPAD? 220*2 : 220)
#define UI_FONT_SIZE             (_IPAD? 20 : 16)

Short and easy :D

like image 37
Felix Avatar answered Mar 01 '26 17:03

Felix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!