[英]Get device image scale (e.g. @1x, @2x and @3x)
I have an app that uses a service to get some icons. 我有一个使用服务获取一些图标的应用程序。
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; 通过这项服务,我可以获得任何大小的任何图像,所以我计划得到3张图像(@ 1x,@ 2x和@ 3x)并将它们存储在BBDD上,然后获得使用这三种图像之一的比例; or maybe get only the one according with the device scale. 或者只能获得符合设备规模的那个。
But the thing is, how can I get the device scale (@1x, @2x and @3x) programmatically? 但问题是,如何以编程方式获得设备规模(@ 1x,@ 2x和@ 3x)?
Both Obj-c and Swift are welcomed ;) 欢迎Obj-c和Swift;)
Use 使用
[UIScreen mainScreen].scale;
this will give you the exact scale as per device. 这将为您提供按设备精确的比例。
In Swift 3 在Swift 3中
UIScreen.main.scale
Cheers. 干杯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.