关于ios device dpi

本文探讨了iOS设备的像素密度(dpi)差异及其对屏幕适配的影响,通过解析苹果官方文档,展示了如何根据设备类型计算dpi,确保应用在不同设备上的兼容性和视觉一致性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

不同的apple设备dpi不同,根据官网提供的数据


http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIScreen_Class/Reference/UIScreen.html

scale

The natural scale factor associated with the screen. (read-only)

@property(nonatomic, readonly) CGFloatscale
Discussion

This value reflects the scale factor needed to convert from the default logical coordinate space into the device coordinate space of this screen. The default logical coordinate space is measured using points, where one point is approximately equal to 1/160th of an inch. If a device’s screen has a reasonably similar pixel density, the scale factor is typically set to 1.0 so that one point maps to one pixel. However, a screen with a significantly different pixel density may set this property to a higher value.

Availability
  • Available in iOS 4.0 and later.


应用要在缩放显示等做到在不同设备间的兼容性,就必须做以下判断:

void calScreenDpi(float& dpi)

{

float scale = 1;

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {

scale = [[UIScreen mainScreen] scale]; //得到屏幕分辨率

}

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

dpi = 132 * scale;

} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {

dpi = 163 * scale;

} else {

dpi = 160 * scale;

}

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值