Declaration
compose().layoutPriority(value: number)nonisolated func layoutPriority(_ value: Double) -> some ViewParameters
value*numberThe priority by which a parent layout apportions space to the child.
Discussion
Views typically have a default priority of 0 which causes space to be
apportioned evenly to all sibling views. Raising a view's layout
priority encourages the higher priority view to shrink later when the
group is shrunk and stretch sooner when the group is stretched.
HStack {
Text("This is a moderately long string.")
.font(.largeTitle)
.border(Color.gray)
Spacer()
Text("This is a higher priority string.")
.font(.largeTitle)
.layoutPriority(1)
.border(Color.gray)
}In the example above, the first Text element has the default
priority 0 which causes its view to shrink dramatically due to the
higher priority of the second Text element, even though all of their
other attributes (font, font size and character count) are the same.
A parent layout offers the child views with the highest layout priority all the space offered to the parent minus the minimum space required for all its lower-priority children.
See also
More in Layout.
- alignmentGuideSets the view's vertical alignment.
- aspectRatioConstrains this view's dimensions to the specified aspect ratio.
- containerCornerOffsetAdjusts the view's layout to avoid the container view's corner insets for the specified edges.
- containerRelativeFramePositions this view within an invisible frame with a size relative to the nearest container.
- controlSizeSets the size for controls within this view.
- defaultScrollAnchorAssociates an anchor to control which part of the scroll view's content should be rendered by default.
- dynamicTypeSizeSets the Dynamic Type size within the view to the given value.
- fixedSizeFixes this view at its ideal size.
- flipsForRightToLeftLayoutDirectionSets whether this view mirrors its contents horizontally when the layout direction is right-to-left.
- framePositions this view within an invisible frame.
- geometryGroupIsolates the geometry (e.g. position and size) of the view from its parent view.
- gridCellAnchorSpecifies a custom alignment anchor for a view that acts as a grid cell.