Evenly space multiple views within a container view

后端 未结 29 3044
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 06:14

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

29条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 06:45

    I was able to solve this entirely in IB:

    1. Make constraints to align the center Y of each of your subviews to the bottom edge of the superview.
    2. Set the multiplier of each of these constraints to 1/2n, 3/2n, 5/2n, …, n-1/2n where n is the number of subviews you are distributing.

    So if you have three labels, set the multipliers to each of those constraints to 0.1666667, 0.5, 0.833333.

提交回复
热议问题