Auto Layout is making my life difficult. In theory, it was going to be really useful when I switched, but I seem to fight it all of the time.
I\'ve made a demo proje
Very quick Interface Builder solution:
For any number of views to be evenly spaced within a superview, simply give each an "Align Center X to superview" constraint for horizontal layout, or "Align Center Y superview" for vertical layout, and set the Multiplier to be N:p
(NOTE: some have had better luck with p:N
- see below)
where
N = total number of views
, and
p = position of the view including spaces
First position is 1, then a space, making the next position 3, so p becomes a series [1,3,5,7,9,...]. Works for any number of views.
So, if you have 3 views to space out, it looks like this:
EDIT Note: The choice of N:p
or p:N
depends on the relation order of your alignment constraint. If "First Item" is Superview.Center, you may use p:N
, while if Superview.Center is "Second Item", you may use N:p
. If in doubt, just try both out... :-)