如何使用MonoTouch获得iPhone / iPad的宽度和高度?

时间:2011-03-25 07:37:24

标签: c# iphone ipad xamarin.ios resolution

我需要使用MonoTouch获取iPhone / iPad的宽度和高度。

如何以编程方式获取?

3 个答案:

答案 0 :(得分:49)

要获取设备的屏幕尺寸,请致电UIScreen.MainScreen.Bounds。它会返回一个RectangleF的屏幕大小。

答案 1 :(得分:9)

要获得宽度,

UIScreen.MainScreen.Bounds.Width

要获得身高,

UIScreen.MainScreen.Bounds.Height

答案 2 :(得分:1)

使用 UIScreen.MainScreen.Bounds 获取屏幕的大小。 它返回屏幕的点值,而不是像素大小。

UIScreen.MainScreen.Scale ,非视网膜显示每点返回1.0像素,视网膜显示每点2.0像素。

UIScreen.MainScreen.Bounds.Size.Width * UIScreen.MainScreen.Scale 将获得宽度(以像素为单位)。