sbtgE
sbtgE

Reputation: 65

How to setup Xcode project for Retina?

I am trying to build my application with retina resolution (2048x1536) but using :

NSLog(@"resolution from xcode %f %f", [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);

I always get 1024x768 resolution. any ideas how to setup retina resolution?

Upvotes: 1

Views: 1404

Answers (1)

ckhan
ckhan

Reputation: 4791

You're getting the value in points, not pixels. From Apple's docs:

Points Versus Pixels

In iOS there is a distinction between the coordinates you specify in your drawing code and the pixels of the underlying device. When using native drawing technologies such as Quartz, UIKit, and Core Animation, you specify coordinate values using a logical coordinate space, which measures distances in points. This logical coordinate system is decoupled from the device coordinate space used by the system frameworks to manage the pixels on the screen. The system automatically maps points in the logical coordinate space to pixels in the device coordinate space, but this mapping is not always one-to-one. This behavior leads to an important fact that you should always remember:

One point does not necessarily correspond to one pixel on the screen.

The purpose of using points (and the logical coordinate system) is to provide a consistent size of output that is device independent. The actual size of a point is irrelevant. The goal of points is to provide a relatively consistent scale that you can use in your code to specify the size and position of views and rendered content. How points are actually mapped to pixels is a detail that is handled by the system frameworks. For example, on a device with a high-resolution screen, a line that is one point wide may actually result in a line that is two pixels wide on the screen. The result is that if you draw the same content on two similar devices, with only one of them having a high-resolution screen, the content appears to be about the same size on both devices.

Upvotes: 4

Related Questions