Stack view is a good option to give less number of constraints to the storyboard items. If we are using stack view then we don’t need to give constraints to each label or button or any object, we can directly place labels or buttons or anything according to our need in stack and using stack properties align them and just give constraints to the stack view not the inside objects to the stack view.
Types
There are two types of Stack view as follows-:
1. Horizontal stack view -> we can place the objects which we have to display horizontally.
2. Vertical stack view-> we can place the objects which we have to display vertically.
For Example: In storyboard take one horizontal stack view, place three labels on it. Labels will take there position automatically. Now select Stack view and pin it from both side of the view i.e right and left and give vertical spacing from bottom or top. In this way you will give constraints to the stack view.
Properties of Stack view
Select the stack view, in attribute inspector you can see many properties that are mentioned below.
1. Axis-> For horizontal or vertical Stack View.
2. Alignment-> It tells the alignment of the objects in the stack view, for example if we select fill option then labels will fill in the stack view,if we select top option then labels will display at the top inside the stack view. so we can select It accordingly.
3. Distribution-> It is related to the area covered by the objects in the stack view. We can change it accordingly.
4. Spacing-> It tells distance between the objects.
In the same way we can use vertical stack view also.
0 Comment(s)