Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the device's scale factor?

I've been using UIGraphicsBeginImageContextWithOptions() and I noticed that the last field in that method is a scalefactor. And the apple docs says, if I want to set it to 0.0, then it will use the default scale factor of the device's main screen. Is there a way to get that default scale factor via property or method?

like image 681
ManOx Avatar asked Dec 24 '12 07:12

ManOx


People also ask

What is device scale factor?

This scaling factor is called the device pixel ratio in web APIs and device scale factor in Chromium code. A UI will always be the same size in DIPs regardless of how many pixels are actually used to display it. To go from physical pixels to DIPs we divide the physical pixel dimensions by the device scale factor.

What is scale factor in IOS?

iPhone X has a high-resolution display with a scale factor of @3x. For glyphs and other flat, vector artwork, it's best to provide resolution-independent PDFs. For rasterized artwork, provide both @3x and @2x versions of your artwork. See Image Size and Resolution and Custom Icons.

What is Native scale factor?

The natural scale factor associated with the screen ... This value reflects the scale factor needed to convert from the default logical coordinate space into the device coordinate space of this screen... Here is their description of nativeScale : The native scale factor for the physical screen.


2 Answers

The device's scale factor is a property of UIScreen. You can obtain it by:

[UIScreen mainScreen].scale; 

Documentation here.

like image 121
jrturton Avatar answered Oct 13 '22 23:10

jrturton


Swift 3+ version:

UIScreen.main.scale 
like image 20
Paulo Venturi Avatar answered Oct 13 '22 23:10

Paulo Venturi