I'd like to have some views fixed on the top of the screen, some other on the bottom and a single fixed size view in the equal distance between the top and bottom views.
I cannot figure out how to do this with Autolayout constraints. Do I need to add some spacer views to the UI, or calculate the desired position programatically?
You can do this with only one additional view. It'd look like this:
There'd be vertical spacing constraints between
stuff_on_top
&middle_view
and betweenmiddle_view
&stuff_on_bottom
.fixed size view
would be centered horizontally and vertically inmiddle_view
.The other way of doing this would be two put two spacer views: between
stuff_on_top
&middle_view
and betweenmiddle_view
&stuff_on_bottom
. Then you'd add a constraint that heights of spacing views are equal.Check out this category: https://github.com/jrturton/UIView-Autolayout
Then you can do something as simple as this...
And you get an output like this:
Edit:
I didn't see the interface-builder tag and just jumped to conclusions... An interface builder alternative would work similar to above.. You would need to have three main views, one pinned to the top and the other pinned to the bottom.. Then one with a flexible width that is pinned to the other two views.
You can then centre a fourth view with a fixed height in your middle view. This will then give you the result you are looking for
I code this https://github.com/damienromito/UIView-AutoYPositioning
But I think a solution with AutoLayout exist...