關於ios device 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;

    }

}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章