2

I'm trying to customise the design for XS Max. Previously I just identified the device by checking the main.bound.screen.height, which, for XS Max, according to this site: https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions, should return 896.0, right?

The Xcode 10.0 XS Max simulator returns 812.0 as screen height (the same goes for XR, which should have the same screen points), though. Any idea how to fix this?

enum IPhone: String {
  case SE, normal, plus, X, XSMax

  init?(height: CGFloat) {
    switch height {
    case 568: self = .SE
    case 667: self = .normal
    case 736: self = .plus
    case 812: self = .X
    case 896: self = .XSMax
    default:
      return nil
    }
  }
}

struct Design {
  static var iPhone = IPhone(height: UIScreen.main.bounds.height)!
}

In the viewDidLoad() of the view controller:

print("screen height: \(UIScreen.main.bounds.height), iPhone: \(Design.iPhone.rawValue)")
nontomatic
  • 2,003
  • 2
  • 24
  • 38
  • When i execute `print(UIScreen.main.bounds.size)` in `AppDelegate`s `didFinishLaunchingWithOptions` function it correctly prints **(414.0, 896.0)** in iPhone XS Max as well as iPhone XR simulator. – André Slotta Sep 18 '18 at 12:54
  • That's weird, I tried there and I get 812.0. Official Xcode release. – nontomatic Sep 18 '18 at 13:16
  • Xcode 10.0 (10A255)? Did you try to reset your simulator? And you are sure that you are not using iPhone XS simulator? Since **812.0** would be correct in this case. – André Slotta Sep 18 '18 at 13:18
  • Yes, 10A255. I've only installed it yesterday. It shows the same for iPhone XR. Th other simulators show the correct size. – nontomatic Sep 18 '18 at 13:42
  • I tried it with a new project and everything works correctly! So there must be a bug in my actual project. So it's on my end. Thanks for the heads up. – nontomatic Sep 18 '18 at 16:37
  • I looked though the whole code but it puzzles me what I could have done in this project for the simulator to respond with an incorrect value for the command print(UIScreen.main.bounds.size). Any ideas? – nontomatic Sep 19 '18 at 07:47

1 Answers1

3

Ok, after some searching I've found the answer to my question here: UIScreen MainScreen Bounds returning wrong size

Turns out, Xcode will guess the size of the screen by going through the launch images you've provided. Can you believe that? So if you didn't provide an image in the proper size for the new XS Max it will fall back to the biggest launch image it finds. That's why in a new project without launch images it worked fine.

I've provided launch images for XS Max and XR and now the screen sizes are correct.

nontomatic
  • 2,003
  • 2
  • 24
  • 38
  • Yeah right. I did not think about at. Kind of related problem: https://stackoverflow.com/questions/32641240/ios-9-xcode-7-application-appears-with-black-bars-on-top-and-bottom – André Slotta Sep 19 '18 at 09:26