ruselli ruselli - 1 year ago 140
Swift Question

Make autolayout contraints to fill different screen sizes in Swift with variable vertical spaces

I want to make my autolayout to fill all the screen sizes from iphone 5s to 8s. The solution I'm looking for is making vertical spaces greater if the screen is bigger. But, I haven't figure it out, I know that I can fix vertical spaces equals or greater than, but it does not work.

The first image is iPhone 5s, and the second is iPhone 8s, the elements in 8s screen should have more vertical space in the second screen. I would try any suggestion.

enter image description here

Answer Source

Based on your UI elements, I suggest to put it in a vertical Stack view. Then you have to fix some constraints to fill the whole screen like this :

  • Stack View.Top = Top Layout Guide.Bottom + Standard //Constraint to the top of the screen
  • Bottom Layout Guide.Top = Stack View.Bottom + Standard //Constraint to the bottom of the screen
  • Axis : vertical
  • Alignement : Fill
  • Distribution : Fill equally or proportionnaly or other
  • Spacing between each view

Try this. Here is Apple Documentation about Auto Layout if you want to go any further or see some examples : Apple documentation - Stack vviews

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download