How does one get UI_USER_INTERFACE_IDIOM() to work with iPhone OS SDK < 3.2

后端 未结 8 1524
旧时难觅i
旧时难觅i 2020-11-28 04:30

Apple advises using the following code to detect whether running on an iPad or iPhone/iPod Touch:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {         


        
8条回答
  •  北海茫月
    2020-11-28 05:10

    I do this to get the code to compile in both 3.1.3 and 3.2:

    BOOL iPad = NO;
    #ifdef UI_USER_INTERFACE_IDIOM
    iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
    #endif
    if (iPad) {
    // iPad specific code here
    } else {
    // iPhone/iPod specific code here
    }
    

    I also wrote a quick blog post about it here: http://www.programbles.com/2010/04/03/compiling-conditional-code-in-universal-iphone-ipad-applications/

提交回复
热议问题