<!--
{
  "availability" : [
    "macOS: 10.12.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSGridView",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSGridView"
  },
  "title" : "NSGridView"
}
-->

# NSGridView

A container that aligns views in a flexible grid of rows and columns.

```
class NSGridView
```

## Overview

A grid view helps you lay out content, such as photos or thumbnails, in a row-column arrangement similar to a spreadsheet. Within a grid view, an item that occupies a single row-column intersection is represented by an [`NSGridCell`](/documentation/AppKit/NSGridCell) object.

## Topics

### Creating a Grid View

[`init(numberOfColumns:rows:)`](/documentation/AppKit/NSGridView/init(numberOfColumns:rows:))

Creates a newly allocated grid view object with the specified number of columns and rows.

[`init(views:)`](/documentation/AppKit/NSGridView/init(views:))

Creates a newly allocated grid view object with the specified array of arrays of views.

[`init(frame:)`](/documentation/AppKit/NSGridView/init(frame:))

Creates a newly allocated grid view object with the specified frame rectangle.

[`init(coder:)`](/documentation/AppKit/NSGridView/init(coder:))

Creates a newly allocated grid view object from the coder.

### Getting Information About the Grid

[`numberOfRows`](/documentation/AppKit/NSGridView/numberOfRows)

The number of rows in the grid view.

[`numberOfColumns`](/documentation/AppKit/NSGridView/numberOfColumns)

The number of columns in the grid view.

[`index(of:)`](/documentation/AppKit/NSGridView/index(of:)-32sdd)

Returns the index of the specified grid column.

[`row(at:)`](/documentation/AppKit/NSGridView/row(at:))

Returns the grid row object at the specified index.

[`column(at:)`](/documentation/AppKit/NSGridView/column(at:))

Returns the grid column object at the specified index.

[`index(of:)`](/documentation/AppKit/NSGridView/index(of:)-6zs2o)

Returns the index of the specified grid row.

### Adding, Removing, and Moving Rows

[`addRow(with:)`](/documentation/AppKit/NSGridView/addRow(with:))

Adds an array of views to a new row.

[`insertRow(at:with:)`](/documentation/AppKit/NSGridView/insertRow(at:with:))

Inserts the array of view objects into the grid view at the index.

[`removeRow(at:)`](/documentation/AppKit/NSGridView/removeRow(at:))

Removes the row from the grid view at the index.

[`moveRow(at:to:)`](/documentation/AppKit/NSGridView/moveRow(at:to:))

Moves the specified row to the new row location.

### Adding, Removing, and Moving Columns

[`addColumn(with:)`](/documentation/AppKit/NSGridView/addColumn(with:))

Adds a new column containing the array of views.

[`insertColumn(at:with:)`](/documentation/AppKit/NSGridView/insertColumn(at:with:))

Inserts the array of view objects at the specified index.

[`removeColumn(at:)`](/documentation/AppKit/NSGridView/removeColumn(at:))

Removes the column from the grid view at the specified index.

[`moveColumn(at:to:)`](/documentation/AppKit/NSGridView/moveColumn(at:to:))

Moves the specified column to a new column location.

### Managing Grid Spacing and Alignment

[`sizedForContent`](/documentation/AppKit/NSGridView/sizedForContent)

The default value for row and column sizes.

[`columnSpacing`](/documentation/AppKit/NSGridView/columnSpacing)

The column spacing for the grid view.

[`rowSpacing`](/documentation/AppKit/NSGridView/rowSpacing)

The row spacing for the grid view.

[`rowAlignment`](/documentation/AppKit/NSGridView/rowAlignment)

The row alignment for the grid view.

[`xPlacement`](/documentation/AppKit/NSGridView/xPlacement)

The placement of the cell within the grid column.

[`yPlacement`](/documentation/AppKit/NSGridView/yPlacement)

The placement of the cell within the grid row.

### Creating and Merging Cells

[`cell(atColumnIndex:rowIndex:)`](/documentation/AppKit/NSGridView/cell(atColumnIndex:rowIndex:))

Returns the grid cell object at the specified column and row index.

[`cell(for:)`](/documentation/AppKit/NSGridView/cell(for:))

Returns the grid cell object that contains the given view or one of its ancestors.

[`mergeCells(inHorizontalRange:verticalRange:)`](/documentation/AppKit/NSGridView/mergeCells(inHorizontalRange:verticalRange:))

Expands the cell at the top-leading corner of the horizontal and vertical range to cover the entire area.



---

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)