The Uistackview provided by IOS9 simplifies layout operations, which are somewhat like liner layout in Android. Previously without Uistackview can also make similar effects, but to add a lot of constraints, see the head is big, using the Uistackview, constraints have been simplified.
Uistackview, what is not well understood is the distribution property, which has the following values:
0 , Uistackviewdistributionfillequally,uistackviewdistributionfillproportionally, Uistackviewdistributionequalspacing,uistackviewdistributionequalcentering,} ns_enum_available_ios (9_0);
It is important to note that the internal Uistackview is also implemented through constraints, so that sufficient and correct constraints must be provided to use it well.
1.UIStackViewDistributionFill
Fill, just fill it up. There are 2 kinds of situations.
The size of the case 1,stackview is fixed
, the size of the StackView is fixed, then it contains 4 sub-views will be filled with the entire stackview, how to allocate the size of these 4 sub-views? This will require us to provide constraint to achieve. If the contraint we offer is not correct, problems will arise. It is recommended to add 3 view height contraint, and the sum of these 3 heights is less than the actual stackview height, so stackview can adjust the fourth view to fill the effect.
There is no limit to the size of the case 2,stackview.
In the case of vertical layout, if the height of the StackView is not constrained,
We removed the bottom constraint of the stackview. Thus, as long as we provide detailed 4 sub-view height constraints, StackView will automatically adjust the height, wrapping content, much like the linear layout in Android.
Look at the effect
2.UIStackViewDistributionFillEqually
This is a good understanding, it will automatically adjust the height, so that they are highly consistent.
also exists in 2, when the height of the StackView is constrained, we do not need to add height constraints to the sub-view, the system will do for us.
When the height of the StackView is not constrained, we must provide a height constraint on a sub-view, allowing the system to calculate the height of the remaining sub-view and the height of the stackview.
3.UIStackViewDistributionFillProportionally
Scaled by the original scale. Where does the original ratio come from? Of course, we added the constraint.
This property, which is generally stackview, is constrained by the height of the 4 subview, and the stackview can be scaled according to their default constraints.
Understanding of IOS Uistackview