关于ios device dpi

本文介绍了如何根据不同Apple设备的屏幕像素密度(DPI)来调整应用程序的显示效果,确保了在不同设备上的一致性和兼容性。

不同的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)  CGFloat scale
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;

    }

}



评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值