2

I have implemented this code for defining my constants:

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

#if (IS_IPAD)
CGFloat const scrollSizeWidth = 768.0f;
CGFloat const scrollSizeHeight = 1004.0f;
#else
CGFloat const scrollSizeWidth = 320.0f;
CGFloat const scrollSizeHeight = 460.0f;
#endif

But it always display 320.0f and 460.0f for my variables.

UPDATE: As k3a user found UI_USER_INTERFACE_IDIOM does not work for iOS 8.3, because it's not longer a define it's a static inline.

Check this answer as well: link

6
  • #ifdef UI_USER_INTERFACE_IDIOM is broken in Xcode 6.3+ as it is no longer a preprocessor define Commented Apr 26, 2015 at 14:44
  • @k3a oh shooot, really? I've not checked it yet Commented Apr 26, 2015 at 16:22
  • Yup. I've noticed it as my app loaded iPhone nibs when compiled with Xcode 6.3+. Here is the new definition of that symbol: static inline UIUserInterfaceIdiom UI_USER_INTERFACE_IDIOM() { return ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? [[UIDevice currentDevice] userInterfaceIdiom] : UIUserInterfaceIdiomPhone); } Commented Apr 26, 2015 at 16:59
  • 1
    @k3a yeah I think the solution we can use [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) Commented Apr 28, 2015 at 8:19
  • yep, but the original code part "#ifdef UI_USER_INTERFACE_IDIOM" now doesn't work as UI_USER_INTERFACE_IDIOM is not a define but a function instead ;) mentioned it so the people know... Commented Apr 28, 2015 at 9:59

2 Answers 2

3

Change:

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

to

#ifdef UI_USER_INTERFACE_IDIOM
#define IS_IPAD (UI_USER_INTERFACE_IDIOM == UIUserInterfaceIdiomPad)
#else
#define IS_IPAD (false)
#endif
Sign up to request clarification or add additional context in comments.

1 Comment

sorry its work but now I get just 768.0f 1004.0f; I mean at any time
2

If UIUserInterfaceIdiomPad is not a preprocessor symbol, then it can't be used in preprocessor conditionals.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.