iOS get physical screen size programmatically?

前端 未结 11 1945
情话喂你
情话喂你 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:48

    You might need use [UIScreen mainScreen].scale;

    CGFloat scale = [UIScreen mainScreen].scale;
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    
    CGFloat physicalWidth = screenRect.size.width * scale;
    CGFloat physicalHeight = screenRect.size.height * scale;
    

提交回复
热议问题