What is the unit of measurement in Xcode
Asked Answered
S

3

23

This might sound silly but when i'm working with sizes in Xcode, the total frame size is equal to 320 * 568 ( width * height ). I'm fine with that. But the resolution of the phone is actually different. The iphone 4S is 640*960 & the 5 and next generations are 640*1136.

I know the last one is exactly double of what xcode is using as units, so my question is :

What unit of measurement does XCode use? If it pixels, why not use the phone size/resolution as reference?

Sparker answered 10/6, 2014 at 13:29 Comment(4)
Don't know if I uderstand your issue correctly, but I've extended my answer to try to help you better.Pylle
i've added correct answer.Tildy
the unit is points – the pixels comes from the points by scale-factor.Joscelin
Thanks :P But I've had my answer 5 years ago ^^Sparker
P
30

It uses points. In retina devices, 1 point equals four pixels. In non-retina devices, 1 points equals 1 pixel.

Check out apple's documentation on drawing and printing on ios. https://developer.apple.com/library/ios/documentation/2ddrawing/conceptual/drawingprintingios/GraphicsDrawingOverview/GraphicsDrawingOverview.html#//apple_ref/doc/uid/TP40010156-CH14-SW7

Specially the section "Points Versus Pixels"

Edit To answer your iphone 4S vs 5 and next generation question. These are actual screen sizes. The resolutions are different. The iPhone 4S and 4 screens are 320x480 points, or 640x960 pixels. iPhone 5, 5C and 5S screens are 320x568 points, or 640x1136 pixels. If you are working with xibs, you may be seeing one of the previous sizes because xibs have a size defined. That's where auto layout constraints come in. You tell in the xib or storyboard how you want the elements to be resized/relocated in the screen. You may be using struts and springs to decide how to relocate items in your view instead of auto layout. It's ok. Even if your xib / storyboard is iphone5 size, if you check the size of the screen in your viewDidAppear methods when running the app on a iPhone4/4S simulator or device, you will see that your view bounds have the size of the corresponding device. It's better to use points instead of pixels because it helps the developer abstract from resolutions. You don't have to bother about how many pixels are a point, you just locate items at points in the screen and let the system take care of the resolution for you.

Pylle answered 10/6, 2014 at 13:31 Comment(3)
I've read that points vs Pixels depends on the PPP (points per pixel) ratio, and 1 point equals exactly one pixel only when using 72pi (because one pixel = 1/72th of a point). So that's why i had ruled this answer out in the first place. But i'm guessing your link will make everything clearer for me ;-)Sparker
For points vs. pixels and printer's points, see my answer here #8687624Aceldama
For completeness, here's another I asked on the topicAlyose
T
11

Xcode 10.1, Swift 4.2 answer

Xcode uses points. But in case of next explanation what is point and how much pixels in point -> it depends what retina device are you using. Basicaly on non-retina devices 1 point = 1pixel. On iphone 6plus and newer "plus" models, apple added 3x resolution. enter image description here

On normal retina devices 1 point = 4 pixels, NOT 2!! then apple packing that pixels into point. At iPhone plus models apple also uses downsampling with factor 1.15 which means for example, if you have 1242*2208 then it should be devided on 1.15 and you get your 1080*1920 fullHD on your device. https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions

enter image description here

I believe that the top answer, which is:

It uses points. In retina devices, 1 point equals two pixels. In non-retina devices, 1 points equals 1 pixel.

is wrong because of outdate. I provided a link to developer.apple.com.

https://developer.apple.com/documentation/uikit/uiscreen/1617836-scale

enter image description here

Tildy answered 25/4, 2018 at 13:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.