Declaration
compose().gridCellColumns(count: number)nonisolated func gridCellColumns(_ count: Int) -> some ViewParameters
count*numberThe number of columns that the view should consume when placed in a grid row.
Return value
A view that occupies the specified number of columns in a grid row.
Discussion
By default, each view that you put into the content closure of a
GridRow corresponds to exactly one column of the grid. Apply the
gridCellColumns(_:) modifier to a view that you want to span more
than one column, as in the following example of a typical macOS
configuration view:
Grid(alignment: .leadingFirstTextBaseline) {
GridRow {
Text("Regular font:")
.gridColumnAlignment(.trailing)
Text("Helvetica 12")
Button("Select...") { }
}
GridRow {
Text("Fixed-width font:")
Text("Menlo Regular 11")
Button("Select...") { }
}
GridRow {
Color.clear
.gridCellUnsizedAxes([.vertical, .horizontal])
Toggle("Use fixed-width font for new documents", isOn: $isOn)
.gridCellColumns(2) // Span two columns.
}
}The Toggle in the example above spans the column that contains
the font names and the column that contains the buttons:
changes the merged cell to use anchor alignment, rather than the
usual alignment guides. For information about the behavior of
anchor alignment, see View.gridCellAnchor(_:).
As a convenience you can cause a view to span all of the Grid
columns by placing the view directly in the content closure of the
Grid, outside of a GridRow, and omitting the modifier. To do
the opposite and include more than one view in a cell, group the views
using an appropriate layout container, like an HStack, so that
they act as a single view.
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.