iOS和Universal WIndows应用程序中的屏幕密度 [英] Density of screen in iOS and Universal WIndows App

查看:84
本文介绍了iOS和Universal WIndows应用程序中的屏幕密度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道Windows 10/8/8.1和iOS中的屏幕密度. 我使用DisplayMetrics在Android中获得了屏幕密度,但是在UWP和iOS中找不到这样的选项/属性. 那么,是否有任何属性可以用来获取UWP和IOS中的屏幕密度.

Hi I need to know the density of screen in windows 10/8/8.1 and iOS. I got screen density in Android using DisplayMetrics but I find no such option/property available in UWP and iOS. So Is there any property through which I can get screen density in UWP and IOS.

推荐答案

更新-2018年6月8日

UPDATE - June 8th 2018

Xamarin.Essentials为开发人员的移动应用程序提供了跨平台API.

Xamarin.Essentials provides developers with cross-platform APIs for their mobile applications.

Android,iOS和UWP提供了独特的操作系统和平台API,开发人员可以利用Xamarin在C#中访问所有API. Xamarin.Essentials提供了一个跨平台API,该API可与任何Xamarin.Forms,Android,iOS或UWP应用程序一起使用,无论用户界面如何创建,都可以从共享代码中对其进行访问. https://github.com/xamarin/Essentials

Android, iOS, and UWP offer unique operating system and platform APIs that developers have access to all in C# leveraging Xamarin. Xamarin.Essentials provides a single cross-platform API that works with any Xamarin.Forms, Android, iOS, or UWP application that can be accessed from shared code no matter how the user interface is created. https://github.com/xamarin/Essentials


您现在可以查询设备的显示信息,而不必管理所有单独的平台代码段.


You can now query the device's display information without having to manage all of the individual platform code pieces.

设备显示信息- https://docs.microsoft.com/en-us/xamarin/essentials/device-display

在您的课程中添加对Xamarin.Essentials的引用:

Add a reference to Xamarin.Essentials in your class:

using Xamarin.Essentials;

以下信息通过API公开:

The following information is exposed through the API:

// Get Metrics
var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;

// Orientation (Landscape, Portrait, Square, Unknown)
var orientation = mainDisplayInfo.Orientation;

// Rotation (0, 90, 180, 270)
var rotation = mainDisplayInfo.Rotation;

// Width (in pixels)
var width = mainDisplayInfo.Width;

// Height (in pixels)
var height = mainDisplayInfo.Height;

// Screen density
var density = mainDisplayInfo.Density;


有用链接:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆