SlideShare a Scribd company logo
UISTACKVIEW
PROVIDES A STREAMLINED INTERFACE FOR LAYING OUT A COLLECTION OF VIEWS
IN EITHER A COLUMN OR A ROW.
DON’T NEED YOU !



I HAVE AUTOLAYOUT FOR THAT…
AUTOLAYOUT
AutoLayout !
Auto Layout dynamically calculates the size and
position of all the views in your view hierarchy,
based on constraints placed on those views
UISTACKVIEW
The Real AutoLayout
Stack views 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 ?????
BEFORE WE BEGIN…
CHCR PRIORITIES ???
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
CONTENT HUGGING, COMPRESSION RESISTANCE PRIORITY
https://littlebitesofcocoa.com/69-compression-resistance-content-hugging
(CHCR PRIORITIES)
ATTRIBUTES
▸ Axis
▸ Alignment
▸ Distribution
▸ Spacing
ALIGNMENT | DISTRIBUTION | SPACING
Source : https://developer.apple.com/reference/uikit/uistackview
AXIS
SPACING
ALIGNMENT : HORIZONTAL STACKVIEW
▸ Top
▸ Center
▸ Bottom
▸ Fill
ALIGNMENT : VERTICAL STACKVIEW
▸ Leading
▸ Center
▸ Trailing
▸ Fill
DISTRIBUTION (1/3)
▸ Fill
▸ Fill Equally
▸ Fill Proportionally 

(Test in code !)
▸ Equal Centering
▸ Equal Spacing
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.
DISTRIBUTION (3/3)
▸ Fill Equally : 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.
POSITIONING AND SIZING THE 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.
GETTING HANDS DIRTY !
LET’S CODE !
XCode
Define the position only.
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
PROGRAMMATICALLY
UIView UIStackView
addSubview: addArrangedSubview:
insertSubview:atIndex: insertArrangedSubview:atIndex:
subviews arrangedSubviews
PECULIARITIES
▸ Non-rendering Subclass of UIView
▸ Be careful with removeArrangedSubview: method. (Avoid It)
▸ hidden property is animatable !
USEFUL LINKS : UISTACKVIEW
▸ https://www.raywenderlich.com/114552/uistackview-tutorial-
introducing-stack-views
▸ http://www.runtimecrash.com/2015/09/17/exploring-uistackview/
▸ https://developer.apple.com/reference/uikit/uistackview
▸ http://www.thinkandbuild.it/introduction-to-uistackview/
▸ https://www.raizlabs.com/dev/2016/04/uistackview/
▸ https://spin.atomicobject.com/2016/06/22/uistackview-distribution/
▸ http://angelolloqui.com/blog/36-Oddities-of-UIStackView
USEFUL LINKS : CHCR PRIORITIES
▸ https://littlebitesofcocoa.com/69-compression-resistance-content-hugging
▸ https://developer.apple.com/library/content/documentation/
UserExperience/Conceptual/AutolayoutPG/AnatomyofaConstraint.html#//
apple_ref/doc/uid/TP40010853-CH9-SW19
▸ https://krakendev.io/blog/autolayout-magic-like-harry-potter-but-real
▸ http://tuchangwei.github.io/2015/09/14/Cocoa-Autolayout-content-
hugging-vs-content-compression-resistance-priority/
▸ http://www.iosinsight.com/content-hugging-and-compression-resistance-
explained/
LASTLY, ON A COMPLETELY 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/

More Related Content

PDF
Declarative UIs with Jetpack Compose
PDF
Memory friendly UIScrollView
PPTX
Android jetpack compose | Declarative UI
PDF
Amazon GameLift – 김성수 (AWS 솔루션즈 아키텍트)
PDF
Implementing Domain-Driven Design (Study Group) Chapter 3 - Context Maps
DOC
Apostila formatando o pc
PPTX
SOLID - Teoria e Prática
PDF
Jetpack Compose a new way to implement UI on Android
Declarative UIs with Jetpack Compose
Memory friendly UIScrollView
Android jetpack compose | Declarative UI
Amazon GameLift – 김성수 (AWS 솔루션즈 아키텍트)
Implementing Domain-Driven Design (Study Group) Chapter 3 - Context Maps
Apostila formatando o pc
SOLID - Teoria e Prática
Jetpack Compose a new way to implement UI on Android

What's hot (14)

ODP
Dependency Injection in Spring in 10min
PPTX
MySql:Introduction
PDF
Netflix in the Cloud
PDF
React Native - Getting Started
PDF
From SQL to NoSQL -- Changing Your Mindset
PDF
Symfony tips and tricks
PPTX
Jetpack Compose.pptx
PDF
게임사를 위한 Amazon GameLift 세션 - 이정훈, AWS 솔루션즈 아키텍트
PDF
MySQL: Indexing for Better Performance
PPTX
AWS CloudFormation Session
PPT
principles of object oriented class design
PDF
JavaScriptCore.framework の普通な使い方 #cocoa_kansai
PPTX
Introduction of sql server indexing
PDF
NestJS - O framework progressivo
Dependency Injection in Spring in 10min
MySql:Introduction
Netflix in the Cloud
React Native - Getting Started
From SQL to NoSQL -- Changing Your Mindset
Symfony tips and tricks
Jetpack Compose.pptx
게임사를 위한 Amazon GameLift 세션 - 이정훈, AWS 솔루션즈 아키텍트
MySQL: Indexing for Better Performance
AWS CloudFormation Session
principles of object oriented class design
JavaScriptCore.framework の普通な使い方 #cocoa_kansai
Introduction of sql server indexing
NestJS - O framework progressivo
Ad

Similar to UIStackView : More than an Introduction (20)

PDF
UIStackView – Tom Bowden – Dec 2015 – Eventacular Inc
PDF
Autolayout primer
PDF
Auto Layout Under Control @ Pragma conference 2013
PDF
Manual Layout Revisited
PDF
iOS Layout Overview
PDF
Layout with Stack View, Table View, and Collection View
PDF
Adjusting to Auto Layout (Tutorial / Tips for iOS Auto Layout)
PDF
Understanding Auto Layout
PDF
Desigining for auto_layout
PDF
Lviv MD Day 2015 Костянтин Бичков "iOS Autolayouts – це добре!"
PPT
Autolayout in iOS
PDF
Understanding stack views
PDF
Auto layout and stack views
PDF
Auto Layout
PDF
Autolayout
PDF
Autolayout
PDF
Auto Layout Priorities - CocoaConf 2016 Seattle
PDF
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 06)
PDF
Tackling Auto Layout
PDF
MOPCON 2014 - Best software architecture in app development
UIStackView – Tom Bowden – Dec 2015 – Eventacular Inc
Autolayout primer
Auto Layout Under Control @ Pragma conference 2013
Manual Layout Revisited
iOS Layout Overview
Layout with Stack View, Table View, and Collection View
Adjusting to Auto Layout (Tutorial / Tips for iOS Auto Layout)
Understanding Auto Layout
Desigining for auto_layout
Lviv MD Day 2015 Костянтин Бичков "iOS Autolayouts – це добре!"
Autolayout in iOS
Understanding stack views
Auto layout and stack views
Auto Layout
Autolayout
Autolayout
Auto Layout Priorities - CocoaConf 2016 Seattle
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 06)
Tackling Auto Layout
MOPCON 2014 - Best software architecture in app development
Ad

Recently uploaded (6)

PPTX
Introduction to Packet Tracer Course Overview - Aug 21 (1).pptx
DOC
证书学历UoA毕业证,澳大利亚中汇学院毕业证国外大学毕业证
DOC
Camb毕业证学历认证,格罗斯泰斯特主教大学毕业证仿冒文凭毕业证
PPTX
ASMS Telecommunication company Profile
PDF
6-UseCfgfhgfhgfhgfhgfhfhhaseActivity.pdf
PDF
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf
Introduction to Packet Tracer Course Overview - Aug 21 (1).pptx
证书学历UoA毕业证,澳大利亚中汇学院毕业证国外大学毕业证
Camb毕业证学历认证,格罗斯泰斯特主教大学毕业证仿冒文凭毕业证
ASMS Telecommunication company Profile
6-UseCfgfhgfhgfhgfhgfhfhhaseActivity.pdf
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf

UIStackView : More than an Introduction

  • 1. UISTACKVIEW PROVIDES A STREAMLINED INTERFACE FOR LAYING OUT A COLLECTION OF VIEWS IN EITHER A COLUMN OR A ROW.
  • 2. DON’T NEED YOU !
 
 I HAVE AUTOLAYOUT FOR THAT…
  • 3. AUTOLAYOUT AutoLayout ! Auto Layout dynamically 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 Stack views 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.
  • 5. INTRINSIC CONTENT SIZE ????? BEFORE WE BEGIN… CHCR PRIORITIES ???
  • 6. 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
  • 7. CONTENT HUGGING, COMPRESSION RESISTANCE PRIORITY https://littlebitesofcocoa.com/69-compression-resistance-content-hugging (CHCR PRIORITIES)
  • 8. ATTRIBUTES ▸ Axis ▸ Alignment ▸ Distribution ▸ Spacing
  • 9. ALIGNMENT | DISTRIBUTION | SPACING Source : https://developer.apple.com/reference/uikit/uistackview
  • 10. AXIS
  • 12. ALIGNMENT : HORIZONTAL STACKVIEW ▸ Top ▸ Center ▸ Bottom ▸ Fill
  • 13. ALIGNMENT : VERTICAL STACKVIEW ▸ Leading ▸ Center ▸ Trailing ▸ Fill
  • 14. 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) ▸ Fill Equally : 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 SIZING THE 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.
  • 20. Define the position only. 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
  • 21. PROGRAMMATICALLY UIView UIStackView addSubview: addArrangedSubview: insertSubview:atIndex: insertArrangedSubview:atIndex: subviews arrangedSubviews
  • 22. PECULIARITIES ▸ Non-rendering Subclass of UIView ▸ Be careful with removeArrangedSubview: method. (Avoid It) ▸ hidden property is animatable !
  • 23. USEFUL LINKS : UISTACKVIEW ▸ https://www.raywenderlich.com/114552/uistackview-tutorial- introducing-stack-views ▸ http://www.runtimecrash.com/2015/09/17/exploring-uistackview/ ▸ https://developer.apple.com/reference/uikit/uistackview ▸ http://www.thinkandbuild.it/introduction-to-uistackview/ ▸ https://www.raizlabs.com/dev/2016/04/uistackview/ ▸ https://spin.atomicobject.com/2016/06/22/uistackview-distribution/ ▸ http://angelolloqui.com/blog/36-Oddities-of-UIStackView
  • 24. USEFUL LINKS : CHCR PRIORITIES ▸ https://littlebitesofcocoa.com/69-compression-resistance-content-hugging ▸ https://developer.apple.com/library/content/documentation/ UserExperience/Conceptual/AutolayoutPG/AnatomyofaConstraint.html#// apple_ref/doc/uid/TP40010853-CH9-SW19 ▸ https://krakendev.io/blog/autolayout-magic-like-harry-potter-but-real ▸ http://tuchangwei.github.io/2015/09/14/Cocoa-Autolayout-content- hugging-vs-content-compression-resistance-priority/ ▸ http://www.iosinsight.com/content-hugging-and-compression-resistance- explained/
  • 25. LASTLY, ON A COMPLETELY 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/