如何获得iOS设备屏幕的高度和宽度

问题描述:


可能重复:

IPhone / IPad:如何以编程方式获取屏幕宽度?

如何获得与屏幕相关的方向高度和宽度?

考虑各种iOS设备和方向,获取当前屏幕分辨率的最简单方法是什么,包括高度和宽度?

Accounting for the various iOS devices and orientations, what is the simplest approach to getting the current screen resolution, including height and width?

UIScreen 是您的朋友。

UIScreen is your friend here.

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;