我怎样才能获得UI_USER_INTERFACE_IDIOM

时间:2011-09-30 06:25:42

标签: iphone ios ios4

我如何获得UI_USER_INTERFACE_IDIOM,我不清楚它是如何工作的,有人可以指导我吗?

1 个答案:

答案 0 :(得分:4)

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    // iPad device
} else {
    // iPhone / iPod touch device
}

来自Apple Header文件:

/* The UI_USER_INTERFACE_IDIOM() macro is provided for use when deploying to a version of the iOS less than 3.2. If the earliest version of iPhone/iOS that you will be deploying for is 3.2 or greater, you may use -[UIDevice userInterfaceIdiom] directly. */
#define UI_USER_INTERFACE_IDIOM() ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? [[UIDevice currentDevice] userInterfaceIdiom] : UIUserInterfaceIdiomPhone)