Layout fundamentals
Arrange views inside built-in layout containers like stacks and grids.
Overview
Use layout containers to arrange the elements of your user interface. Stacks and grids update and adjust the positions of the subviews they contain in response to changes in content or interface dimensions. You can nest layout containers inside other layout containers to any depth to achieve complex layout effects.
[Image]
To fine-tune the position, alignment, and other elements of a layout that you build with layout container views, see Layout adjustments. To define custom layout containers, see Custom layout. For design guidance, see Layout in the Human Interface Guidelines.
Topics
Choosing a layout
Statically arranging views in one dimension
Dynamically arranging views in one dimension
Grouping data with lazy stack viewsCreating performant scrollable stacksLazyHStackLazyVStackPinnedScrollableViews
Statically arranging views in two dimensions
Dynamically arranging views in two dimensions
Layering views
Adding a background to your viewZStackzIndex(_:)background(alignment:content:)background(_:ignoresSafeAreaEdges:)background(ignoresSafeAreaEdges:)background(_:in:fillStyle:)background(in:fillStyle:)overlay(alignment:content:)overlay(_:ignoresSafeAreaEdges:)overlay(_:in:fillStyle:)backgroundMaterialcontainerBackground(_:for:)containerBackground(for:alignment:content:)ContainerBackgroundPlacement