UIStackView provides a streamlined interface for laying out a collection of views in either a vertical or horizontal orientation. It handles the layout of its arranged subviews and their content sizes, alignments, spacing and distribution. The stack view's position and size must be defined, while it will calculate the frames of its arranged subviews based on constraints and the specified distribution, alignment and spacing attributes.
AUTOLAYOUT
AutoLayout !
Auto Layoutdynamically calculates the size and
position of all the views in your view hierarchy,
based on constraints placed on those views
4.
UISTACKVIEW
The Real AutoLayout
Stackviews lets you leverage the power of
Auto Layout, creating user interfaces that can
dynamically adapt to the device’s orientation,
screen size, and any changes in the available
space.
INTRINSIC CONTENT SIZE
▸The minimum space needed to express the full view
content without squeezing or clipping that data
https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/
AnatomyofaConstraint.html#//apple_ref/doc/uid/TP40010853-CH9-SW21
DISTRIBUTION (1/3)
▸ Fill
▸Fill Equally
▸ Fill Proportionally
(Test in code !)
▸ Equal Centering
▸ Equal Spacing
15.
DISTRIBUTION (2/3)
▸ Fill
▸Attempts to fill the space along the axis with the items.
▸ Sizes each item via its intrinsicContentSize.
▸ Uses each item’s contentCompressionResistancePriority and
contentHuggingPriority to determine which items to grow or shrink.
▸ contentCompressionResistancePriority – The view with the lowest
value gets truncated when there is not enough space to fit
everything’s intrinsicContentSize.
▸ contentHuggingPriority – The view with the lowest value gets
expanded beyond its intrinsicContentSize when there is leftover
space to fill.
16.
DISTRIBUTION (3/3)
▸ FillEqually : Resizes each item equally along the axis to fill the
available space. Also takes into account spacing between items.
▸ Fill Proportionally : Resizes each item by proportionally
distributing the extra space based on their intrinsicContentSize
along the axis.
▸ Equal Centering :Sizes each item based on its
intrinsicContentSize and spaces them all equally along the axis.
Uses spacing as a minimum value.
▸ Equal Spacing : Sizes each item based on its
intrinsicContentSize and spaces them all equally from each
others center along the axis. Uses spacing as a minimum value.
17.
POSITIONING AND SIZINGTHE STACK VIEW
‣ You are responsible for defining the
position and (optionally) the size of the
stack view. The stack view then manages
the layout and size of its content.
Define the positiononly.
Define the stack’s size along its axis.
Define the stack’s size perpendicular to its
axis.
Define the size and position of the stack
view
https://developer.apple.com/reference/uikit/uistackview
COMMON UISTACKVIEW LAYOUTS
LASTLY, ON ACOMPLETELY DIFFERENT NOTE,
ONE IMPORTANT THING…
▸ Don’t use custom views for navigation bar. It leads to
choppy UX !
▸ Use native Navigation bar only and customise if needed !
▸ http://www.appcoda.com/customize-navigation-status-
bar-ios-7/
▸ https://www.natashatherobot.com/navigation-bar-
interactions-ios8/