With the update of the Apple product line, I updated the software and tried to find out the physical size of the screens of the new devices in pixels.
With the iPhone XS
it's clear:
- the width / height is 1125 / 2436 pix,
- ScalingFactor 3,
- physically it's 375 / 812 points in width / height (like Iphone X).
With the iPhone XR
is also clear:
- the width / height of 750 / 1624 pix,
- ScalingFactor 2,
- physically also produces 375 / 812 points in height / width.
But it's not clear with the iPhone XS Max
- Apple indicates a width / height of 1242 / 2688 pixels,
but my calculations give data like the iPhone XS:
- width / height 1125 / 2436 pix,
- ScalingFactor 3,
- physically get 375/ 812 width / height points.
I think with Device.Info.PixelScreenSize.Height
and Device.Info.PixelScreenSize.Width
, I divide into Device.Info.ScalingFactor
, then I recheck Xamarin.Essentials
, namely DeviceDisplay.ScreenMetrics
, then I also divide it into Device.Info.ScalingFactor
.
Where is the truth? What to take for reliable data?
P.S. Sorry for Google Translate
EDIT: 1. App.cs
public partial class App : Application
{
public static int ScreenWidth;
public static int ScreenHeight;
public static Size ScreenSize;
...
2. AppDelegate.cs
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
App.ScreenWidth = (int)UIScreen.MainScreen.Bounds.Width;
App.ScreenHeight = (int)UIScreen.MainScreen.Bounds.Height;
App.ScreenSize = new Size(UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);
...
3. MainPageViewModel.cs
public class MainPageViewModel
{
public double DeviceHeightInPixels { get; set; }
public double DeviceWidthPixels { get; set; }
public double Coefficient { get; set; }
public double PhysicalHeightInPixels { get; set; }
public double PhysicalWidthInPixels { get; set; }
public double DeviceHeightInPixelsFromMetrics { get; set; }
public double DeviceWidthPixelsFromMetrics { get; set; }
public int AppScreenHeight { get; set; }
public int AppScreenWidth { get; set; }
public double AppScreenSizeHight { get; set;}
public double AppScreenSizeWidth { get; set; }
public MainPageViewModel()
{
var metrics = DeviceDisplay.ScreenMetrics;
DeviceHeightInPixels = Device.Info.PixelScreenSize.Height;
DeviceWidthPixels = Device.Info.PixelScreenSize.Width;
Coefficient = Device.Info.ScalingFactor;
PhysicalHeightInPixels = DeviceHeightInPixels / Coefficient;
PhysicalWidthInPixels = DeviceWidthPixels / Coefficient;
DeviceHeightInPixelsFromMetrics = metrics.Height;
DeviceWidthPixelsFromMetrics = metrics.Width;
AppScreenHeight = App.ScreenHeight;
AppScreenWidth = App.ScreenWidth;
AppScreenSizeHight = App.ScreenSize.Height;
AppScreenSizeWidth = App.ScreenSize.Width;
}
}