What are pixels and points in iOS? - iphone

from UIImage reference:
#property(nonatomic, readonly) CGSize size
The dimensions of the image, taking orientation into account.
Discussion
In iOS 4.0 and later, this value reflects the logical size of the image and is measured in points. In iOS 3.x and earlier, this value
always reflects the dimensions of the image measured in pixels.
What's the difference between pixels and points in iOS?

A pixel on iOS is the full resolution of the device, which means if I have an image that is 100x100 pixels in length, then the phone will render it 100x100 pixels on a standard non-retina device. However, because newer iPhones have a quadrupled pixel density, that same image will render at 100x100 pixels, but look half that size. The iOS engineers solved this a long time ago (way back in OS X with Quartz) when they introduced Core Graphics' point system. A point is a standard length equivalent to 1x1 pixels on a non-retina device, and 2x2 pixels on a retina device. That way, your 100x100 image will render twice the size on a retina device and basically normalize what the user sees.
It also provides a standard system of measurement on iOS devices because no matter how the pixel density changes, there have always been 320x480 points on an iPhone screen and 768x1024 points on an iPad screen.*
But at the same time, you can basically disregard the documentation considering that retina devices were introduced with iOS 4 at a minimum, and I don't know of too many people still running iOS 3 on a newer iPhone. But if such a case arises, your UIImage would need to be rendered at exactly twice its dimensions in pixels on a retina iPhone to make up for the pixel density difference.
*Starting with the iPhone 5, the iPhone's dimensions are now no longer standardized. Please use the appropriate APIs to retrieve the screen's dimensions or use layout constraints.

The Ultimate Guide To iPhone Resolutions
These guys did an awesome job, take a look here — The Ultimate Guide To iPhone Resolutions.

Using data from http://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions I set up the formula sqrt(pointWidth^2+pointHeight^2)/diagonalInches to figure out how many points each phone displayed per inch.
Results:
iPhone 2G, 3G, 3GS, 4, 4s = 164.825201164068082 Points Per Inch
iPhone 5, 5s = 162.9846618550346903
iPhone 6 = 162.8061416117083255
iPhone 6 Plus = 153.535954278463216
As you can tell a point is roughly the same size on each phone. Using the same webopage, you can set up the same formula with the pixel values, and you'll notice large irregularities due to higher pixel densities on the newer phones.

iOS pixels, points, units
We should review them in context of
coordinate systems
absolute and relative positioning
Differences
pixels(absolute) - pixel-based coordinate systems of current screen. Is used in very specific cases. For example CGImage (The width/height, in pixels, of the required image), CGContext
points(virtual pixels, logical pixels)(absolute) - default Point-based coordinate systems. It is a kind of density independent pixel - dp in Android.
units - unit coordinate systems(relative). From 0.0 to 1.0. For example CALayer.anchorPoint
[iOS Frame vs Bounds]

Related

What are the differences in UX between an iPhone 5 and iPhone 6 Plus that are relevant to an app?

Previous iPhone upgrades were uncomplicated. A resolution increase just meant an improvement in quality but no change in size, while the iPhone 4S-5 transition was simple since the device only added less than an inch to the vertical dimension, without changing anything else (pixel density, horizontal resolution, etc)
But the 6 Plus seems a bit more complicated because there are two major changes:
Instead of the resolution being a simple multiple of the older one, the 6 Plus first appears to draw at 3x to an offscreen buffer, then scales this down to 1920x1080.
The PPI has changed by a non-integral amount (from 326 PPI on 5S to 401 PPI on the 6 Plus).
This is making it hard for me to understand the following:
How much more screen real-estate do I REALLY have on a 6-Plus, in physical terms, on the X and Y axis, as compared to an iPhone 5?
Will my buttons be smaller/larger on the 6-Plus? Because of the different ppi and the scaling?
The physical ratio of the screens is easily derived from the physical dimensions themselves! Since the aspect ratio has been maintained, the ratio of the diagonals (5.5/4 and 4.7/4) should easily give you the increase in horizontal and vertical dimensions the iPhone 6 and 6 Plus provide over the iPhone 5.
Thus, you have 37.5% more space in EACH DIMENSION (width and height) in the 6-Plus, and 17.5% more space in the iPhone 6, as compared to the iPhone 5. The area ratios (although less useful) are 89% and 38% respectively.
The button-size calculation is more involved. To make things easy, let's consider the render-size (in inches) of a 100-points button. Now:
a. On non-retina devices (iPhone 1 to 3GS), 100-points translate to 100-pixels. Because of 163 ppi, their physical size would be 0.6135 inches
b. On retina devices (iPhone 4 to iPhone 6), 100-points translate to 200-pixels (2x scaling). because of 326 ppi, their physical size would be: 0.6135 inches
(of course we know from experience that buttons are the same physical size as on non-retina devices)
c. On retina "HD" devices (iPhone 6-Plus). 100-points FIRST translate to 300-pixels (3x scaling). They are then scaled DOWN to ~0.87 of their original pixel size (i.e. the 2208x1242 pixel-buffer is scaled to 1920x1080). This means, 300-pixels are now drawn as ~261 pixels.
Because of 401 ppi, their physical size would be: 0.65 inches
So buttons on a 6 Plus are 6% larger physically, given the SAME point size. For most practical purposes, this is a negligible difference, and can be ignored. And on the upside the slightly larger buttons may even improve usability of your app.
Thus a button or UI-element of a specific point-size, should have ALMOST the same physical size on both an iPhone 5/6 versus an iPhone 6 Plus.
Comment: This indicates that all the roundabout scaling and ppi-changes were effectively for Apple to achieve both:
1. A higher ppi on a new higher-end class of devices
2. Keeping the logical-points to physical-inches translation as CLOSE to the original ratio as possible, so that buttons etc remain the same size on all devices.
So you dont need to be concerned about button sizes. Just account for the 37.5% additional space available to you on in each dimension on iPhone 6 Plus, and 17.5% in the iPhone 6, in your app and you should be good to go.

Iphone 5 game resolution

I have a developer working on a game for me for ios for iPhone 5. He stated the resolution we must use for the game is 320 x 568, but the iphone 5 has a resolution of 640 x 1136 and he stated that this is the resolution for the graphics and not the game leveling design. The game is a 2D maze game.
I am still learning, so any help would be greatly appreciated. Which resolution is the correct resolution? Why is it half of what apple states?
Thanks in advance
Here's the story. When Apple introduced the iPhone 4, it introduced the "Retina Display". That is, the iPhone 4 had a screen with twice as many pixels on it than the previous iPhones. So to compensate, Apple came up with the screen points system. It works like this:
-On non-retina devices, 1 point = 1 pixel
-On retina devices, 1 point = 2 pixels
-On any device, the programmer's coordinates are done in points.
-On any device, the art assets should be done using pixels
Example: I have a 200x200 pixel image used on retina devices. When I load the image into a view, the size of the view is 100x100 points.
In order to make sure your image is loaded properly, you have to use the #2x suffix. If you have a 200x200 pixel image "myImage.png", it will be loaded as 200x200 points and will be scaled up on retina devices. If instead you name the image "myImage#2x.png", instead it will interpret the image as 100x100 points, and will scaled down on non-retina devices. You can also have two versions of an image (Apple recommends 2 images although it isn't strictly necessary). If you have both 100x100 pixel "myImage.png" and 200x200 pixel "myImage#2x.png", it will interpret them as two versions of the same image, and will use the #2x one on retina devices and the other one on non-retina devices. In both cases, the image will be interpreted as 100x100 points.
You might also want to take a look at Apple's High Resolution Guide.

iPhone and iPad screen resolution

I m developing a universal app.I want to know will the screen resolutions (320 * 480) for iphone and (768 *1024 )in iPad will work for all iphone's (iPhone 3g,iPhone4 etc) and all iPads.Because based on these screen resolutions I m setting textField's, UILabel's width in both iPhone and iPad.Will these work for retinas and nonretinas ?
Retina iPhones and iPads use the same coordinate system as non-Retina devices. Presently all iPads have a logical coordinate space of 768x1024, and all iPhones except the iPhone 5 have a logical coordinate space of 320x480. Your code should work fine on both Retina and non-Retina devices.
On an iPhone 5, your app will be shown with black bars at the top of the screen unless you tell iOS that you want to use the full screen by including a Default.png for the extended screen resolution.
You can check the screen resolution with [[UIScreen mainScreen] bounds]. This value will be the same on Retina and non-Retina devices. You can detect a Retina device by checking the value of [[UIScreen mainScreen] scale]; the value here is the number of physical pixels per unit of logical coordinate space (1.0 for non-Retina, 2.0 for Retina).
UIKit and CoreGraphics work with points rather than pixels.
Both the retina and non-retina devices have the same number of points, but a different amount of pixels. This means that the same point values can mean a different pixel value on different devices.
To answer your question, yes the same layout UILabel widths will display the same on retina and non retina devices.
From the Apple Developer Documentation :
In iOS, all coordinate values and distances are specified using floating-point values in units referred to as points. The measurable size of a point varies from device to device and is largely irrelevant. The main thing to understand about points is that they provide a fixed frame of reference for drawing.
Have a look at the Points vs. Pixels section in the View Programming Guide:
http://developer.apple.com/library/ios/documentation/windowsviews/conceptual/viewpg_iphoneos/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40009503-CH2-SW15
You can always use the capabilities to get the OS and do what you need to your interface.
var pattern:RegExp = /iphone5/i;
var str:String = Capabilities.os;
if (str.search(pattern)==0)
{
trace('iPhone5 Detected. Alter height.');
}else{
trace('No need to change dimensions if developing at 960x640');
}

High resolution images and the retina display

Am a newbie to iOS App development and to design. I was wondering about these 2 questions:
can I create a high-resolution image & use it for all the devices (be it retina or non-retina)? (why should one create a low-resolution image intentionally for a non-retina device? why can't everything be simply high-resolution?) ... I hope it isn't a dumb question!
And what do we exactly mean by 'high-resolution' here? '1024pixels X 1024pixels' ? how high is 'high'' really for a retina display?
Any help please?
"High Resolution" means twice the pixels in each dimension on iOS (and OSX). So if you have an image that is 23x10 pixels on a non-retina display, the high resolution version of it must be 46x20 pixels in size.
If you name your high resolution images like this: lowResImageName#2x.png, the system will automatically choose the high res image on retina devices.
As others have said, you use special low-res images to maximize quality (because you can choose to leave fine details out of a low-res image, etc.) and minimize memory footprint (because the non-retina variants have had half the RAM of the retina versions so far).
It also helps to think in non-retina pixels, because one non-retina pixel equals one "display point", the unit in which iOS measures sizes.
iOS devices' resolution is as follows:
standard retina
iPhone, iPod Touch 320 x 480 640 x 960
iPad 768 x 1024 1536 x 2048
iPhone 5 - 640 x 1136
Why create a low-resolution image? Because it will automagically be used on non-retina devices, saving memory.
For some images that will work just fine, but for certain ones (if your image has some fine text for example), they will come out looking jagged or distorted when scaled down automatically. There may also be cases when you want something displayed differently(I've had occasional images with cool gradient effects that just don't look right on a low res device, so I've had to remove some detail in the low res image to make it look okay).
The other answer is also correct in that if you allow for both cases, low res devices will only load the low res images into memory, so the app will be using less memory. This is only an optimization for those cases, but it is still helpful since typically you can assume that the low res devices will have less memory to begin with since they are older.
Retina graphics, the high resolution graphics you are mentioning, should be double the point values for width and height. What I mean by that is, on all iPhone-sized devices, the size of the screen is 320 points by 480 points. On non-retina devices, translates to 320 pixels by 480 pixels. On retina devices, this translates into 640 pixels by 960 pixels. Everything is double in both the horizontal and vertical directions.
What this means, is you should have two versions of all your image assets. So if you have image that you want on the screen that is 44 points wide by 44 points tall, you should have two images ... Image.png which will be 44 pixels by 44 pixels, and Image#2x.png which will be 88 pixels by 88 pixels (for retina devices, this is what the #2x represents).
Why have two versions, and not just the high rez version? Because it takes processing power to 'compress' the larger version into a smaller version. It's much easier to just already have the lower resolution version, and you are saving valuable memory.
The first question was answered by H2CO3. You safe memory on old devices (think of iPhone 3G, many current Apps are terribly slow, yet well-coded apps still work fine)
What does high-resolution mean?
E.g. on a non-retina device you can show some example.png of 300x200 pixels using [UIImage imageNamed:"example.png"].
High-res would mean, you had an additional example#2x.png of 600x400 pixels, i.e. double size. Then you're app size is bigger, both devices have appropriate graphics but you save memory on the old device (Which would have to allocate 4 times the memory with no added improvement for the user, because it still has only a 300x200 pixel-display-space for a 600x400 pixel image).

iphone 4 Simulator reporting 480x320 as the screen size?

I am debugging an application using iPhone 4 Simulator. I have selected it from the simulator menu (device = iPhone 4). When I run the app, the screen size is reported as 480x320 !!??
Is there something I have to modify on this app of mine (originally built for 3G/3gs) in order to make it run on iPhone 4 (yes, I have recreated all artwork as 960x640 and the artwork is on the bundle, but it is scaling it down to half the size... because it is running on 3G/3GS mode, instead of hi res).
running
CGRect cgRect =[[UIScreen mainScreen] bounds];
will result in (0,0,480,320).
Any clues?
thanks for any help.
Recommended read: http://developer.apple.com/iphone/library/documentation/iphone/conceptual/iphoneosprogrammingguide/SupportingResolutionIndependence/SupportingResolutionIndependence.html
One point does not necessarily
correspond to one pixel on the screen.
A sample project, download here.
The iPhone is making the move into resolution independence. This means that things aren't measured in pixels, but in points. Points don't always correspond to pixels.
The screen size of the iPhone 3GS (and previous) is 480x320, in both points an pixels. They correspond on these devices, but in newer devices (like iPhone 4) they do not.
The iPhone 4's screen size is 960x640 in pixels, but its logical screensize is still 480x320 in points.
This allows you to keep your frame, point and size values in their original values and still support larger resolution devices.
On iPhone 4 you need to have #2x somewhere in the name of the image file and it will be used automatically on the higher resolution devices.
When #2x images are loaded, they are loaded as their original resolution, but their size property is halved to be able to work with the logical point measurments.
For instance, an image with an original size of 960x640 will report its size as 480x320 when it's asked for.
instead of bounds use currentMode
CGSize pixelBufferSize = [[[UIScreen mainScreen] currentMode] size];
you will get actual resolution