Search code examples
iosxcodelayoutstoryboarduniversal

iOS Storyboard Layout - Constraint Query


I've been playing around with the Universal design in Xcode and actually quite like it.

While playing I can't seem to work out how to get equal spacing between certain items.

enter image description here

In the above image I would like to have the 3 x red bars equally spaced inside the light blue view.

The best I can do is set the middle red bar to be in the centre of the light blue view and then fix the distance between the other red bars.

Is there any other way to space them out?

For example when you have a UIToolbar you can just place all of the items in the toolbar and then use flexible spaces to equally distribute the items.

Hope this makes sense.


Solution

  • You could do something along the lines of: place the first bar in the center, and then have two clear UIViews filling the space on top and below the middle bar. And then the top and bottom bars could be centered on those clear UIViews (vertically centered in container).

    You could also do something very similar to what you need to do with Toolbars. i.e. place 5 clear views between and outside of the three bars that you care about, and then set them to be equal height. This will force the three bars to be spaced evenly.