MatterGoal
MatterGoal

Reputation: 16430

Autolayout and proportional positioning

I suppose that my situation should be a common problem, but I'm really new to AutoLayout and to me it seems particularly complicated:

I want to make a layout to be suitable with 3.5 inches and 4 inches screens. This is the view for 4 inches displays:

enter image description here

And here is the view for a 3.5 inches display:

3.5 inches display

What I need is essentially make the spaces between the segmented control and the yellow and blue view proportional to the screen size I suppose.

My solution (that doesn't work):

1)Adding constraints for top/bottom vertical spaces of the segment control using less or equal to.

2)Adding constraints to the other views to keep their positions (for example the blue view has a bottom spacing to the main view equal to zero, the yellow view has a fixed top spacing).

In my mind the constraints of point 1) just scale down when the main view scales... but it doesn't happen... and the segment view just move behind the other views maintaining the spacing defined as max value of the "Less then or equal to" definition.

How can I solve this common problem?

Have I to create spacer views for this situation? and in that case how you'd set up them?

Upvotes: 3

Views: 711

Answers (1)

Mark Kryzhanouski
Mark Kryzhanouski

Reputation: 7241

There is an pure autolayout solution:

  1. Add vertical space constraint [yellowView]-(80@500)-[segmentView]
  2. Add second vertical space constraint [segmentView]-(>=5)-[blueView]

Upvotes: 1

Related Questions