iPhone Development 101

iPhone 101

Code Tips




Mailing ListTwitter


iPhone Development 101: User Interface:
iPhone Device & Screen Sizes

To get the screen dimensions (in points) of the current device:

CGRect screenBounds = [[UIScreen mainScreen] bounds];

// Macros:
#define screen_width [ [ UIScreen mainScreen ] bounds ].size.width
#define screen_height [ [ UIScreen mainScreen ] bounds ].size.height

To get the screen scale:

CGFloat screenScale = [[UIScreen mainScreen] scale];

Non-retina devices have a scale of 1.0. Retina devices have a scale of 2.0 or 3.0 (iPhone 8 Plus and iPhone X are 3.0).

Some dimensions common to all screen sizes:

Status Bar
(How to hide the status bar)
20 pts
Navigation Bar 44 pts
Nav Bar/Toolbar Icon 20 x 20 pts (transparent PNG)
Tab Bar 49 pts
Tab Bar Icon 30 x 30 pts (transparent PNGs)

Points vs. Pixels

Apple introduced retina displays starting with the iPhone 4. You don't have to modify your code to support high-res displays; the iOS coordinate system uses points rather than pixels, so the dimensions and position in points of all UI elements remains the same across all devices.

iOS supports high resolution displays via the scale property on UIScreen, UIView, UIImage, and CALayer classes. If you load an image from a file whose name includes the @2x modifier, its scale property is set to 2.0. Similarly an image with a @3x modifier has a scale of 3.0. Otherwise the scale defaults to 1.0.

Retina Graphics

To support high-resolution graphics on devices with retina displays, create a standard size image, and a double-sized image with "@2x" added to the name:

Standard Size: High Resolution:

60 x 20

120 x 40

To refer to an image in your code (or in Interface Builder), just use the filename of the standard sized image. iOS will automatically detect and use the @2x version if the device supports it:

imageView.image = [UIImage imageNamed:@"button.png"];

Adjusting Sizes

Click here to see how to adjust View Frames and Bounds.

Additional References