- NSSize size;
- double scale;
-
-# ifndef __IPHONE_8_0 // iOS 7 SDK or earlier
-
- size = [screen bounds].size; // points, not pixels
- scale = [screen scale]; // available in iOS 4
-
-# else // iOS 8 SDK or later
-
- if ([screen respondsToSelector:@selector(nativeBounds)]) {
- size = [screen nativeBounds].size; // available in iOS 8
- scale = 1; // nativeBounds is in pixels.
-
- /* 'nativeScale' is very confusing.
-
- iPhone 4s:
- bounds: 320x480 scale: 2
- nativeBounds: 640x960 nativeScale: 2
- iPhone 5s:
- bounds: 320x568 scale: 2
- nativeBounds: 640x1136 nativeScale: 2
- iPad 2:
- bounds: 768x1024 scale: 1
- nativeBounds: 768x1024 nativeScale: 1
- iPad Retina/Air:
- bounds: 768x1024 scale: 2
- nativeBounds: 1536x2048 nativeScale: 2
- iPhone 6:
- bounds: 320x568 scale: 2
- nativeBounds: 640x1136 nativeScale: 2
- iPhone 6+:
- bounds: 320x568 scale: 2
- nativeBounds: 960x1704 nativeScale: 3
-
- According to a StackOverflow comment:
-
- The iPhone 6+ renders internally using @3x assets at a virtual
- resolution of 2208x1242 (with 736x414 points), then samples that down
- for display. The same as using a scaled resolution on a Retina MacBook
- -- it lets them hit an integral multiple for pixel assets while still
- having e.g. 12pt text look the same size on the screen.
-
- The 6, the 5s, the 5, the 4s and the 4 are all 326 pixels per inch,
- and use @2x assets to stick to the approximately 160 points per inch
- of all previous devices.
-
- The 6+ is 401 pixels per inch. So it'd hypothetically need roughly
- @2.46x assets. Instead Apple uses @3x assets and scales the complete
- output down to about 84% of its natural size.
-
- In practice Apple has decided to go with more like 87%, turning the
- 1080 into 1242. No doubt that was to find something as close as
- possible to 84% that still produced integral sizes in both directions
- -- 1242/1080 = 2208/1920 exactly, whereas if you'd turned the 1080
- into, say, 1286, you'd somehow need to render 2286.22 pixels
- vertically to scale well.
- */
-
- } else {
- size = [screen bounds].size; // points, not pixels
- scale = [screen scale]; // available in iOS 4
- }
-# endif // iOS 8
-
- size.width = ceilf (size.width / scale);
- size.height = ceilf (size.height / scale);