init(horizontal:vertical:)
Creates a custom alignment value with the specified horizontal and vertical alignment guides.
Declaration
init(horizontal: HorizontalAlignment, vertical: VerticalAlignment)Parameters
- horizontal:
The alignment on the horizontal axis.
- vertical:
The alignment on the vertical axis.
Discussion
SwiftUI provides a variety of built-in alignments that combine built-in HorizontalAlignment and VerticalAlignment guides. Use this initializer to create a custom alignment that makes use of a custom horizontal or vertical guide, or both.
For example, you can combine a custom vertical guide called firstThird with the built-in center guide, and use it to configure a ZStack:
ZStack(alignment: Alignment(horizontal: .center, vertical: .firstThird)) {
// ...
}For more information about creating custom guides, including the code that creates the custom firstThird alignment in the example above, see AlignmentID.