init(alignment:content:)
Creates a horizontal row of child views in a grid.
Declaration
init(alignment: VerticalAlignment? = nil, @ViewBuilder content: () -> Content)Parameters
- alignment:
An optional Verticalalignment for the row. If you don’t specify a value, the row uses the vertical alignment component of the Alignment parameter that you specify in the grid’s Init(alignment:horizontalspacing:verticalspacing:content:) initializer, which is Center by default.
- content:
The builder closure that contains the child views. Each view in the closure implicitly maps to a cell in the grid.
Discussion
Use this initializer to create a GridRow inside of a Grid. Provide a content closure that defines the cells of the row, and optionally customize the vertical alignment of content within each cell. The following example customizes the vertical alignment of the cells in the first and third rows:
Grid(alignment: .trailing) {
GridRow(alignment: .top) { // Use top vertical alignment.
Text("Top")
Color.red.frame(width: 1, height: 50)
Color.blue.frame(width: 50, height: 1)
}
GridRow { // Use the default (center) alignment.
Text("Center")
Color.red.frame(width: 1, height: 50)
Color.blue.frame(width: 50, height: 1)
}
GridRow(alignment: .bottom) { // Use bottom vertical alignment.
Text("Bottom")
Color.red.frame(width: 1, height: 50)
Color.blue.frame(width: 50, height: 1)
}
}The example above specifies trailing alignment for the grid, which is composed of center vertical alignment and trailing horizontal alignment. The middle row relies on the center vertical alignment, but the other two rows specify custom vertical alignments:
[Image]
To override column alignment, use gridColumnAlignment(_:). To override alignment for a single cell, use gridCellAnchor(_:).