iOS get physical screen size programmatically?

前端 未结 11 1963
情话喂你
情话喂你 2020-12-15 03:11

Is this possible? I want the number of inches, not the number of pixels. I know it is approximately 160 ppi. But not exactly.

11条回答
  •  醉话见心
    2020-12-15 03:54

    Maybe Jeff Hay's code can be adapted to include iPad Mini. The trick is to get the device's model identifier. The most recent non-retina iPad is "iPad2,4" and the first iPad mini is "iPad2,5". Now all you need to check is if the screen scaling is 1.0 (non-retina)

    Although this code is not future-proof, you can always add more rules for model identifiers.

    #import 
    
    #define SCREEN_SIZE_IPAD_MINI 7.9
    
        struct utsname systemInfo;
        uname(&systemInfo);
        if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && strcasecmp(systemInfo.machine, "iPad2,5") >= 0 [[UIScreen mainScreen] scale] == 1.0)
            return SCREEN_SIZE_IPAD_MINI
    

提交回复
热议问题