In this blog, I have given a brief introduction about UIStackview introduced in iOS 9, and also explained how can we use UIStackview
iOS 9 has introduced UISTACKVIEW which has made complex UIDesign much easier and saved developer from implementing the number of constraints for giving equal spacing, proportional spacing etc.
According to the requirement, iOS 9 has provided both vertical stack view and horizontal stack view. To create a stack view drag and drop a vertical
stackviewor horizontal stackviewas required.
Now just drag and drop the UI elements in the
stackviewaccording to your requirement. The main benefit we get by using UIStackview is that now we don't have to implement constraints to the UIElements inside StackView but we just have to apply constraints to UIstackview, other elements inside it will automatically get adjusted as per our requirement. From attribute insectorwe can choose how we want inside UIElements to be adjusted for eg. we can choose fill, proportional, equal spacing etc
On the basis of an axis, we can choose how to align the elements into available space. If we select vertical axis, then we can align elements to the leading, trailing and center of the stack view and when we select horizontal axis, then we can align elements to top, center or bottom.
Here are some of the properties that define the how the stack view layout its content.
- axis - stack view’s orientation can be determined by axis property, its orientation can be vertical or horizontal.
- distribution - a layout of the arranged views can be determined to be determined to buy this property, along with the stock’s axis
ment - we can determine whether the stack view lays out its arranged views relative to its layout margins.
- spacing - this property is used to judge the minimum spacing between arranged views.
- alignment - this property determines the layout of the arranged views perpendicular to the stack view’s axis
- isBaselineRelativeArrangement - this property is used to calculate the vertical spacing between views from baselines.