<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/gridCellColumns(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE15gridCellColumnsyQrSiF"
  },
  "title" : "gridCellColumns(_:)"
}
-->

# gridCellColumns(_:)

Tells a view that acts as a cell in a grid to span the specified
number of columns.

```
nonisolated func gridCellColumns(_ count: Int) -> some View
```

## Parameters

`count`

The 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`](/documentation/SwiftUI/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`](/documentation/SwiftUI/Toggle) in the example above spans the column that contains
the font names and the column that contains the buttons:

![A screenshot of a configuration view, arranged in a grid. The grid](images/com.apple.SwiftUI/View-gridCellColumns-1-macOS@2x.png)

> Important: When you tell a cell to span multiple columns, the grid
> changes the merged cell to use anchor alignment, rather than the
> usual alignment guides. For information about the behavior of
> anchor alignment, see ``doc://com.apple.SwiftUI/documentation/SwiftUI/View/gridCellAnchor(_:)``.

As a convenience you can cause a view to span all of the [`Grid`](/documentation/SwiftUI/Grid)
columns by placing the view directly in the content closure of the
[`Grid`](/documentation/SwiftUI/Grid), outside of a [`GridRow`](/documentation/SwiftUI/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`](/documentation/SwiftUI/HStack), so that
they act as a single view.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)