Search code examples
xcodeautolayoutxcode7xcode-ui-testingsize-classes

supporting view on different IOS devices.


  1. My app is supposed to run only on Iphone but apple is testing it on Ipad too. Apparently, the apps can run in Iphone mode on Ipads. How do I know which Ipad will run which Iphone mode (ex: ipad mini air2 = iphone 5 view settings in iphone mode?)?

  2. How can I change the size of my UI based on changing aspect ratio programmatically ? (My views are created through code).


Solution

  • The iPad Pro runs an iPhone 6. The iPad 2 and Air 2 run an iPhone 4s.

    I don't know if there's official documentation for this, but what I did is create a sample app and set the Devices to iPhone only. Then I added

    print(self.view.frame.size) //Swift
    NSLog(@"width = %f, height = %f", self.view.frame.size.width, 
                                      self.view.frame.size.height); //Obj-C
    

    in the default ViewController. This will print the screen size of the view only, and not the entire iPad's screen. I then compared the printed value to the printed value of the same app run in iPhone 6/4s. You can try it too.

    In terms of changing the size of your UI to fit different screen sizes, your best bet is probably AutoLayout. There are many (free, open source) frameworks available that make creating AutoLayout constraints programatically much simpler.

    A few are Stevia, Cartography, SnapKit (Swift) / Masonry (Obj-C), or PureLayout.