0

I am wondering if it possible to override screen size in a setting and reload your app.

I want to do this so that if I have an iPhone X open, for example, I am able to open a debug menu on my app and default override the screen size, reload the app, and have it be testable as the size of an iPhone 6.

I want to do this so that I can test all different screen dimensions without compiling and running the app on all different simulators.

Thanks in advance!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Logan
  • 1,172
  • 9
  • 23
  • This type of on-the-fly switching is supported in Interface Builder, but not in Simulator. You have to switch simulator target to switch devices. – particleman Jun 20 '18 at 14:43
  • If you just want to test the size, and not the actual device, you could just resize the view of your root view controller, but I highly discourage this! – George Green Jun 20 '18 at 17:00

2 Answers2

0

This isn't possible. You need to build and test by running on each differently sized simulator that you wish to test.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
0

What you are asking cannot be done that way, only you can create new window with different frame but to use in another device's screen. But you can change you current view controllers view frames according calculating the aspect ratio of each device and changing the height of you view according to that, or you can make the rect with the local dimensions too.

Make extension use it everywhere:

e.g:

extension UIViewController {
   /* With exact value */
   func convertTo3_5inch() {
       // 320 × 480
       if UIScreen.main.bounds.height >= 480 {
           self.view.frame = CGRect(x: 0, y: 0, width: 320, height: 480)
           self.view.layoutIfNeeded()
       }
   }
   /* With Ratio */
   func convertTo16_9ratio() {
       // 320 * 568
       if UIScreen.main.bounds.height >= 568 {
           self.view.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: (UIScreen.main.bounds.width*16)/9)
           self.view.layoutIfNeeded()
       } else {
           print("Screen size smaller than the size your are converting to")
       }

   }
   /* call this func in button */
   func changeAction() {
       let action = UIAlertController(title: "Options", message: nil, preferredStyle: .actionSheet)
       action.addAction(UIAlertAction(title: "3.5inch", style: .default, handler: { (action) in
           self.convertTo3_5inch()
    }))

       action.addAction(UIAlertAction(title: "5to8plus", style: .default, handler: { (action) in
           self.convertTo16_9ratio()
    }))

       self.present(action, animated: true, completion: .none)
   }
}

Customize according to your need,

Subhajit Halder
  • 1,427
  • 13
  • 21