Evenly space multiple views within a container view

后端 未结 29 2866
佛祖请我去吃肉
佛祖请我去吃肉 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:42

    The correct and easiest way is to use Stack Views.

    1. Add your labels/views to the Stack View:

    1. Select the Stack View and set Distribution to be Equal Spacing:

    1. Add Spacing to nearest neighbor constraints to the Stack View and update frames:

    1. Add Height constraints to all the labels (optional). Needed only for views that does not have Intrinsic Size). Labels for example does not need here height constrains and only need to set numberOfLines = 3 or 0 for example.

    1. Enjoy Preview:

提交回复
热议问题