ios 獲取屏幕尺寸

獲取屏幕尺寸



1.根據像素

UIScreenMode *ScreenMode = [[UIScreen mainScreen] currentMode];

float width = ScreenMode.size.width;

float height = ScreenMode.size.height;

以上代碼在不同設備上,得到的值是不同的。

注意:這種方式獲得的值是以像素爲單位的(The width and height in pixels)。

不同設備上的值爲:

iPhone (3.5 inch): 320 x 480
iPhone Retina (3.5 inch): 640 x 960

iPhone Retina (4.0 inch): 640 x 1136

iPad: 768 x 1024

iPad Retina: 1536 x 2048


2.根據點


CGRect bounds = [[UIScreen mainScreen] bounds];

float width = bounds.size.width;

float height = bounds.size.height;

以上代碼在不同設備上,得到的值是不同的。
注意:這種方式獲得的值是以點爲單位的(Bounds of entire screen in points)。

不同設備上的值爲:

iPhone (3.5 inch): 320 x 480
iPhone Retina (3.5 inch): 320 x 480

iPhone Retina (4.0 inch):320 x 568

iPad: 320 x 480

iPad Retina: 320 x 480



/***************************************************/




發佈了21 篇原創文章 · 獲贊 4 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章