获取设备图像比例(例如@ 1x,@ 2x和@ 3x) [英] Get device image scale (e.g. @1x, @2x and @3x)

查看:127
本文介绍了获取设备图像比例(例如@ 1x,@ 2x和@ 3x)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用服务获取一些图标的应用。

I have an app that uses a service to get some icons.

通过这项服务,我可以得到任何尺寸的图像,所以我计划得到3张图像(@ 1x,@ 2x和@ 3x)并存储它们在BBDD上,然后得到使用这三个中的一个的比例;或者只能获得符合设备规模的那个。

With this service I can get any image of any size, so I've planned to get the 3 images (@1x, @2x and @3x) and store them on the BBDD, and then get the scale to use one of these three; or maybe get only the one according with the device scale.

但问题是,如何以编程方式获得设备规模(@ 1x,@ 2x和@ 3x) ?

But the thing is, how can I get the device scale (@1x, @2x and @3x) programmatically?

欢迎Obj-c和Swift;)

Both Obj-c and Swift are welcomed ;)

推荐答案

使用

[UIScreen mainScreen].scale;

这将为您提供每台设备的精确比例。

this will give you the exact scale as per device.

Swift 3

UIScreen.main.scale

干杯。

这篇关于获取设备图像比例(例如@ 1x,@ 2x和@ 3x)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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