Detecting iPhone 6/6+ screen sizes in point values
The first screen will be the device screen, Note that a launch images for the new phones have to be added before, otherwise the app is running in Zoomed Mode for older apps :
Here is the code I used to check this out. Note: This only works with version iOS 8 and higher:
UIScreen *mainScreen = [UIScreen mainScreen];
NSLog(@"Screen bounds: %@, Screen resolution: %@, scale: %f, nativeScale: %f",
NSStringFromCGRect(mainScreen.bounds), mainScreen.coordinateSpace, mainScreen.scale, mainScreen.nativeScale);
Code for detecting iPhone 6 Plus:
#define IS_PAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_PHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
-(BOOL)iPhone6PlusDevice{
if (!IS_PHONE) return NO;
if ([UIScreen mainScreen].scale > 2.9) return YES; // Scale is only 3 when not in scaled mode for iPhone 6 Plus
return NO;
}
or
-(BOOL) iPhone6PlusUnZoomed{
if ([self iPhone6PlusDevice]){
if ([UIScreen mainScreen].bounds.size.height > 720.0) return YES; // Height is 736, but 667 when zoomed.
}
return NO;
}
Note: If you are checking for iPhone 6 Plus, to adjust the user interface then don´t rely on .nativeScale
, because the simulator and actual device give different results. Due to the comment below. Scale is a CGFloat and thus, code should not check equality, because some floats values may never be equal.
After adding Launch Screen you can utilise the new iPhone sizes, otherwise your app will still look scaled.
Updated for the new iPhones 11, 11 Pro and 11 Pro Max
Size for iPhone 11 Pro Max with @3x scaling, coordinate space: 414 x 896 points and 1242 x 2688 pixels, 458 ppi, device physical size is 3.06 x 6.22 in or 77.8 x 158.0 mm. 6.5" Super Retina XDR display.
Size for iPhone 11 Pro with @3x scaling, coordinate space: 375 x 812 points and 1125 x 2436 pixels, 458 ppi, device physical size is 2.81 x 5.67 in or 71.4 x 144.0 mm. 5.8" Super Retina XDR display.
Size for iPhone 11 with @2x scaling, coordinate space: 414 x 896 points and 828 x 1792 pixels, 326 ppi, device physical size is 2.98 x 5.94 in or 75.7 x 150.9 mm. 6.1" Liquid Retina HD display.
Size for iPhone X Max with @3x scaling (Apple name: Super Retina HD 6.5 display"), coordinate space: 414 x 896 points and 1242 x 2688 pixels, 458 ppi, device physical size is 3.05 x 6.20 in or 77.4 x 157.5 mm.
let screen = UIScreen.main
print("Screen bounds: \(screen.bounds), Screen resolution: \(screen.nativeBounds), scale: \(screen.scale)")
//iPhone X Max Screen bounds: (0.0, 0.0, 414.0, 896.0), Screen resolution: (0.0, 0.0, 1242.0, 2688.0), scale: 3.0
Size for iPhone X/strong> with @2x scaling (Apple name: Super Retina HD 6.1" display), coordinate space: 414 x 896 points and 828 x 1792 pixels, 326 ppi, device physical size is 2.98 x 5.94 in or 75.7 x 150.9 mm.
let screen = UIScreen.main
print("Screen bounds: \(screen.bounds), Screen resolution: \(screen.nativeBounds), scale: \(screen.scale)")
//iPhone X Screen bounds: (0.0, 0.0, 414.0, 896.0), Screen resolution: (0.0, 0.0, 828.0, 1792.0), scale: 2.0
Size for iPhone X/strong> and iPhone X with @3x scaling (Apple name: Super Retina HD 5.8" display), coordinate space: 375 x 812 points and 1125 x 2436 pixels, 458 ppi, device physical size is 2.79 x 5.65 in or 70.9 x 143.6 mm.
let screen = UIScreen.main
print("Screen bounds: \(screen.bounds), Screen resolution: \(screen.nativeBounds), scale: \(screen.scale)")
//iPhone X and X Screen bounds: (0.0, 0.0, 375.0, 812.0), Screen resolution: (0.0, 0.0, 1125.0, 2436.0), scale: 3.0
Size for iPhone 8, 7, 6 Plus and iPhone 8, 7, 6S Plus with @3x scaling (Apple name: Retina HD 5.5), Coordinate space: 414 x 736 points and 1242 x 2208 pixels, 401 ppi, screen physical size is 2.7 x 4.8 in or 68 x 122 mm:
Screen bounds: {{0, 0}, {414, 736}}, Screen resolution: <UIScreen: 0x7f97fad330b0; bounds = {{0, 0}, {414, 736}};
mode = <UIScreenMode: 0x7f97fae1ce00; size = 1242.000000 x 2208.000000>>, scale: 3.000000, nativeScale: 3.000000
Size for iPhone 6 and iPhone 6S with @2x scaling (Apple name: Retina HD 4.7), Coordinate space: 375 x 667 points and 750 x 1334 pixels, 326 ppi, screen physical size is 2.3 x 4.1 in or 58 x 104 mm:
Screen bounds: {{0, 0}, {375, 667}}, Screen resolution: <UIScreen: 0x7fa01b5182d0; bounds = {{0, 0}, {375, 667}};
mode = <UIScreenMode: 0x7fa01b711760; size = 750.000000 x 1334.000000>>, scale: 2.000000, nativeScale: 2.000000
And iPhone 5 for comparison is 640 x 1136, iPhone 4 640 x 960.
Note: Upload LaunchImages otherwise the app will run scaled and not show correct scaling, or screen sizes.
Detecting iPhone 6 and plus
In order to support native resolution on iPhone 6/6+ you need to either
- provide properly sized launch images
- provide XIB file for launch screen
How to detect iPhone 6 (6 plus) on simulator
You have to add the appropriate launch images so the app device/simulator starts using the real size and not a zoomed or emulated size, until you add a launch image for Retina HD 5.5
and Retina HD 4.7
you won't be using the new sizes.
Click the small grey arrow on the Launch Images Source in your Project General Settings and add the appropriate launch images.
What is the target resolution for iPhone 6 Plus apps?
Apple's guideline for all devices is to stop hard coding screen sizes and use Autolayout. If yo are targeting the iPhone 6/6+ you can assume iOS8 and Xcode 6 which makes Autolayout much easier.
It you really want to work to a specific screen resolution, you should use 1242×2208 which is downscaled to 1080x1920 in hardware.
How to detect iPhone 6 or iPhone 6 Plus view size mode programmatically
This works for me tested in iphone 6+ and 6s+
if #available(iOS 8.0, *) {
print("ios greater than 8")
if(UIScreen.mainScreen().bounds.size.height == 667.0 && UIScreen.mainScreen().nativeScale < UIScreen.mainScreen().scale){
// iphone 6+ and 6s+ are in zoomed
print("iphone 6+ and 6s+ zoomed ")
}else{
// iphone 6+ and 6s+ are in standard
print("iphone 6+ and 6s+ standard ")
}
}else{
print("ios less than 8")
}
thanks @k8mil
in iPhone App How to detect the screen resolution of the device
CGRect screenBounds = [[UIScreen mainScreen] bounds];
That will give you the entire screen's resolution in points, so it would most typically be 320x480 for iPhones. Even though the iPhone4 has a much larger screen size iOS still gives back 320x480 instead of 640x960. This is mostly because of older applications breaking.
CGFloat screenScale = [[UIScreen mainScreen] scale];
This will give you the scale of the screen. For all devices that do not have Retina Displays this will return a 1.0f, while Retina Display devices will give a 2.0f and the iPhone 6 Plus (Retina HD) will give a 3.0f.
Now if you want to get the pixel width & height of the iOS device screen you just need to do one simple thing.
CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);
By multiplying by the screen's scale you get the actual pixel resolution.
A good read on the difference between points and pixels in iOS can be read here.
EDIT: (Version for Swift)
let screenBounds = UIScreen.main.bounds
let screenScale = UIScreen.main.scale
let screenSize = CGSize(width: screenBounds.size.width * screenScale, height: screenBounds.size.height * screenScale)
Related Topics
Autolayout Link Two Uilabels to Have the Same Font Size
Xcode 10.2 with Swift 5.0 Compiler - Protocol Inheritance Issue
In Firebase, How to Query the Most Recent 10 Child Nodes
Add a Uiview Above All, Even the Navigation Bar
Ios: Uibutton Resize According to Text Length
Change String Color with Nsattributedstring
How to Play Mp3 Audio from Url in iOS Swift
Nsdateformatter and Current Language in iOS11
How Much Delay of iOS Push Notification
How Does Xcode Find Implicit Target Dependencies
Hide Keyboard for Text Field in Swift Programming Language
Rebuild an Nsarray by Grouping Objects That Have Matching Id Numbers
Unexpected Non-Void Return Value in Void Function Swift3
How to Use Presentmodalviewcontroller to Create a Transparent View
How to Allow User to Pick the Image with Swift
Swift - How to Hide Back Button in Navigation Item