AutoLayout with size classes: Different spacing de

2019-07-31 08:26发布

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.

1条回答
甜甜的少女心
2楼-- · 2019-07-31 08:53

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

查看更多
登录 后发表回答