14

I wonder how I can check if the user has the display set to zoomed mode.

I have tried this:

public var isZoomed: Bool {
    return UIScreen.main().scale < UIScreen.main().nativeScale
}

And also:

#define IS_OS_8_OR_LATER    ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 (IS_IPHONE && ([[UIScreen mainScreen] bounds].size.height == 568.0) && ((IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale == [UIScreen mainScreen].scale) || !IS_OS_8_OR_LATER))
#define IS_STANDARD_IPHONE_6 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0  && IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale == [UIScreen mainScreen].scale)
#define IS_ZOOMED_IPHONE_6 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0 && IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale > [UIScreen mainScreen].scale)
#define IS_STANDARD_IPHONE_6_PLUS (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 736.0)
#define IS_ZOOMED_IPHONE_6_PLUS (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0 && IS_OS_8_OR_LATER && [UIScreen mainScreen].nativeScale < [UIScreen mainScreen].scale)

But I none of them works.

So is there a way to detect if the device is zoomed or even force it to not be zoomed when the app is running?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2636197
  • 3,982
  • 9
  • 48
  • 69
  • I don't know if this would work, so I'm not posting this as an answer. Scroll down on this 2014 Reddit thread ([link]https://www.reddit.com/r/apple/comments/2jcvnj/iphone_6_plus_zoomed_vs_standard/) to waterbed87's post about iPhone5s == iPhone 6 zoom and iPhone6 == iPhone6 plus zoom. Could you compare two things - actual device and full screen bounds - and come up with a zoomed screen? –  Nov 29 '16 at 14:06
  • @dfd thanks for helping out but I found a working swift 3 solution and have posted it – user2636197 Nov 29 '16 at 14:23
  • Curious why you need to know this? It's extremely rare that an app needs to know what device it is actually on or whether the display is zoomed or not. Most apps using the macros in your question are written incorrectly. – rmaddy Nov 29 '16 at 15:40

1 Answers1

26

Working swift 3 solution:

if (UIScreen.main.bounds.size.height == 667.0 && UIScreen.main.nativeScale < UIScreen.main.scale) {
    print("iphone 6 plus")
} else {
    print("none zoomed 6 plus")
}
        
if (UIScreen.main.bounds.size.height == 568.0 && UIScreen.main.nativeScale > UIScreen.main.scale) {
    print("zoomed iphone 6")
} else {
    print("none zoomed")
}
Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
user2636197
  • 3,982
  • 9
  • 48
  • 69
  • 1
    This answer should get the green tick. Works perfect on Swift 3 & 4. – Daniel Fernandez Feb 03 '18 at 19:07
  • @DanielFernandez, How come it worked for you? Shouldn't the `nativeScale` and `scale` comparison in the second `if` be reversed? – Iulian Onofrei Nov 26 '20 at 15:51
  • 1
    See my response for the similar question [here](https://stackoverflow.com/a/65844985/8314394). It is not using hardcoded heights and is more useful for any device size. – Starsky Jan 22 '21 at 12:21
  • Check my answer [here](https://stackoverflow.com/a/65844985/8314394). You can detect the zoomed mode on any device. – Starsky Jan 20 '23 at 14:47