获取iPhone的物理屏幕尺寸(英寸) [英] Getting the physical screen size in inches for iPhone

查看:140
本文介绍了获取iPhone的物理屏幕尺寸(英寸)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以英寸为单位以编程方式获取屏幕尺寸(例如iPhone 4,3.5英寸)。

How can I get the screen size programmatically in inches(for example iPhone 4, 3.5 inches).

通过检测iPhone /我找到了一种方法iPad模型,但硬编码不是我想要的,所以我不是那样的。

I found a way to do it by detecting the iPhone/iPad model but hard coding is not what I want so I am not looking something like that.

推荐答案

这将找到对角屏幕设备大小:

This will find the diagonal screen size of a device:

float scale = [[UIScreen mainScreen] scale];

float ppi = scale * ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? 132 : 163);

float width = ([[UIScreen mainScreen] bounds].size.width * scale);
float height = ([[UIScreen mainScreen] bounds].size.height * scale);

float horizontal = width / ppi, vertical = height / ppi;

float diagonal = sqrt(pow(horizontal, 2) + pow(vertical, 2));

对角线将包含对角线尺寸,屏幕的英寸。

diagonal will contain the diagonal size, in inches, of the screen.

这篇关于获取iPhone的物理屏幕尺寸(英寸)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆