1

In preparation for a possibly bigger screen in the iPhone 6, we can obviously programmatically base layouts around screen bound size, but how do we ensure the custom xib files are formatted? For example, I have a custom UITableViewCell that is set to 320x145 in storyboard. Can I somehow prepare this for a different sized screen?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Jeff Nelson
  • 187
  • 1
  • 10
  • Make you sizes relative to the screen size using layout constraints. That's the way you should be handling it now for 3.5 vs 4 inch screens. You don't even need to set the width of a cell though, since by default, they are the same width as the table view. – rdelmar Jul 10 '14 at 14:58

3 Answers3

2

If you truly need to prepare for something that is rumored, I would suggest the same methods that everyone used when preparing for the iPhone 5:

  1. Download and install latest version of Xcode.
  2. Set a 6-inch launch image for your app. This is how you get new screen height (without it, you will get 1136 px with black margins on top and bottom).
  3. Test your app, and hopefully do nothing else, since everything should work magically if you had set auto resizing masks properly.
  4. If you didn't, adjust your view layouts with proper auto resizing masks or look into Auto Layout if you only want to support iOS 6 going forward.
  5. If there is something you have to do for the larger screen specifically, then it looks like you have to check height of [[UIScreen mainScreen] bounds] (or applicationFrame, but then you need to consider status bar height if it's present) as there seems to be no specific API for that.

Example:

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == new screen height) {
    // code for 6-inch screen
} else if (screenBounds.size.height == 1136) {
    // code for 4-inch screen
}
else {
    // code for 3.5-inch screen
}
Community
  • 1
  • 1
user1947561
  • 1,117
  • 2
  • 8
  • 13
  • What are the downsides to being prepared? It's almost certainly happening. – Matt Shank Jul 10 '14 at 14:50
  • @MattShank Because there is no way to answer this question. We have no idea what the screensize's will be. I'll update my answer to be a little more helpful, though. – user1947561 Jul 10 '14 at 14:51
  • Rumor or not, the screen size won't stay fixed forever, so seems a bit silly to have a bunch of 320 width constants sitting around. – Jeff Nelson Jul 10 '14 at 14:57
  • @JeffNelson literally just updated the answer as you commented, so take a look! – user1947561 Jul 10 '14 at 14:58
  • Thanks! So will auto-layout deal with resizing the width of custom views made in xib files, for example? – Jeff Nelson Jul 10 '14 at 14:59
  • 1
    @JeffNelson Check this [auto layout tutorial](http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2). I don't use .xibs, so can't vouch for that, but I did find this for future reference if you have a problem: http://stackoverflow.com/questions/17127454/issues-with-autolayout-with-custom-views-defined-in-nib-file-and-used-in-storybo. – user1947561 Jul 10 '14 at 15:02
2

Have you looked at the new Xcode6 beta? As far as I can see, we are able to create freeform views there in storyboards:

enter image description here

Looks like this (+ Auto Layout) allows us to be prepared for flexible interface types.

Alex Peda
  • 4,210
  • 3
  • 22
  • 31
1

The absolute best thing that you can do this time around (not just doing a bunch of if's everywhere) is to use Size Classes in your Storyboards.

Whats new in Xcode:

Size classes

Size classes for iOS 8 enable designing a single universal storyboard with customized layouts for both iPhone and iPad. With size classes you can define common views and constraints once, and then add variations for each supported form factor. iOS Simulator and asset catalogs fully support size classes as well.

Community
  • 1
  • 1
Oxcug
  • 6,524
  • 2
  • 31
  • 46