1

I have a UIViewController set up in an UIStoryboard in Interface Builder using size classes.

enter image description here

This looks good on an iPhone 5 with the 4" screen, but on the 5.5" screen of the iPhone 6 Plus the elements are too cramped in the top area of the device. I want to increase the constant of the spacing constraints on iPhone 6 and 6 Plus.

As far as I was able to see that's not possible with size classes, as there is only one size class for all iPhone displays (no matter if 3.5" or 5.5"). What is the way to do this? Maybe something with the constraint multiplier? Still haven't really figured that one out.

Cornelius
  • 4,214
  • 3
  • 36
  • 55

1 Answers1

2

See my answer here:

https://stackoverflow.com/a/20865342/341994

As I explain there, you can't make a spacing constraint value depend on the height of something. But you can make a height constraint depend on the height of something. So try adding an invisible view whose height is proportional to the superview height, and use it as a spacer, with constraints to it. This will push the views down proportionally to the screen height.

I made a quick demo. Look at how the top of the red view is further down on the iPhone 6 than it is on the iPhone 4s:

enter image description here

enter image description here

Community
  • 1
  • 1
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thanks a lot for the answer and the demo! You are doing this by making the height of the spacer view equal to the super view but with a multiplier < 1, right? I tested that in my view controller and a multiplier of 0.05 seems to work ok, except on the 3.5" screen, there the direction pad is off screen. Not sure that can really be fixed this way. – Cornelius Dec 26 '14 at 21:36
  • @Cornelius Off screen? Then there is something wrong with your constraints. – matt Dec 27 '14 at 00:45