Reputation: 4253
I've a ViewController that have some components, UILabels and UITextFields. I wants that the distance between them is uniform, 2 Points Top and Bottom, for example. So far, I adjust manually the distance. I wants know if exists a way to make this automatically. I tried select all UIViews and set constraints, but not works.
Actually layout:
When I tried set all components constraints:
Not works perfectelly:
Upvotes: 0
Views: 87
Reputation: 100549
You can't set that constant spacing by selecting all components , but you can insert them inside a Vertical UIStackview
(emebded in a UIScrollView
) with distribution fillEqually
and set spacing
between items to any constant you want
-> mainView
-> scrollView
->contentView
->stackview
->lbl1
->txtf1
Upvotes: 2
Reputation: 6018
I wants that the distance between them is uniform, 2 Points Top and Bottom, for example.
For this kind of work UIStackView
do the best job. Simply select all view, check Embed In Stack
:
And then specify the Spacing
value (note, that sometimes you also need to change the Axis
parameter, but in most cases initial value is correct for your ui elements):
Result (distance between all labels is 8):
Upvotes: 1