开发者

#define based upon platform [iPhone or iPad]

I'm trying to make my iPhone app compatible with the iPad. In a header file I set up some constants. Because of the larger screen I want some constants used for images to be larger on the iPad than on to the iPhone. I found some suggestions on the internet to accomplish this:

#if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define imgAmcWidth 656.0f
#define imgAmcHeight 36.0f
#else
#define imgAmcW开发者_如何学Goidth    240.0f
#define imgAmcHeight   20.0f
#endif

This seems to satisfy my needs. Unfortunately xcode 4 fails to compile this giving an error: 'Token "[" is not valid in preprocessor..' [LLVM GCC 4.2]. What am I doing wrong?


While probably not the most elegant solution but to prevent a major rewrite of the code I decided to use the following trick:

#define iPad    UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
#define imgAmcWidth         (iPad ? 639.0f : 240.0f)
// etc..


UI_USER_INTERFACE_IDIOM and UIUserInterfaceIdiomPad are not preprocessor things. They are part of iOS, so you should do:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    <define your constants here>
} else {
    <define your constants here>
}

See also this if you plan to support iOS versions previous to 3.2

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜