Overloads
2 ways to call compose().alignmentGuide(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().alignmentGuide(
g: SwiftUI.VerticalAlignment,
options: {
computeValue: (arg0: SymbolicValue) => ScalarLike;
}
)@preconcurrency nonisolated func alignmentGuide(
_ g: VerticalAlignment,
computeValue: @escaping @Sendable (ViewDimensions) -> CGFloat
) -> some ViewParameters
A
VerticalAlignmentvalue at which to base the offset.options.computeValue*(arg0: SymbolicValue) => ScalarLikeA closure that returns the offset value to apply to this view.
Return value
A view modified with respect to its vertical alignment according to the computation performed in the method's closure.
Discussion
Use alignmentGuide(_:computeValue:) to calculate specific offsets
to reposition views in relationship to one another. You can return a
constant or can use the ViewDimensions argument to the closure to
calculate a return value.
In the example below, the weather emoji are offset 20 points from the
vertical center of the HStack.
VStack {
Text("Today's Weather")
.font(.title)
.border(.gray)
HStack {
Text("🌧")
.alignmentGuide(VerticalAlignment.center) { _ in -20 }
.border(.gray)
Text("Rain & Thunderstorms")
.border(.gray)
Text("⛈")
.alignmentGuide(VerticalAlignment.center) { _ in 20 }
.border(.gray)
}
}Changing the alignment of one view may have effects on surrounding views. Here the offset values inside a stack and its contained views is the difference of their absolute offsets.
See also
More in Layout.
- 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.
- gridCellColumnsTells a view that acts as a cell in a grid to span the specified number of columns.