<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/NSCollectionLayoutSpacing",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCollectionLayoutSpacing"
  },
  "title" : "NSCollectionLayoutSpacing"
}
-->

# NSCollectionLayoutSpacing

An object that defines the space between or around items in a collection view.

```
@MainActor class NSCollectionLayoutSpacing
```

## Overview

In a collection view layout, you use a spacing object to specify both the amount of space and the way in which it’s calculated.

You can express spacing using fixed or flexible spacing.

Use *fixed spacing* to provide an exact amount of space. For example, the following code creates exactly 200 points of space between the items in the group.

```objc
[group setInterItemSpacing: [NSCollectionLayoutSpacing fixedSpacing:200.0]];
```

Use *flexible spacing* to provide a minimum amount of space that can grow as more space becomes available. For example, the following code creates at least 200 points of space between the items in the group. As more space becomes available, items are respaced evenly in the additional space.

```objc
[group setInterItemSpacing: [NSCollectionLayoutSpacing flexibleSpacing:200.0]];
```

## Topics

### Creating spacing

[`+  fixedSpacing:`](/documentation/UIKit/NSCollectionLayoutSpacing/fixed(_:))

Creates a space equivalent to the specified number of points.

[`+  flexibleSpacing:`](/documentation/UIKit/NSCollectionLayoutSpacing/flexible(_:))

Creates a space equivalent to or greater than the specified number of points, depending on the available space.

### Getting the spacing value

[`spacing`](/documentation/UIKit/NSCollectionLayoutSpacing/spacing)

The floating-point value of the space.

### Getting the spacing type

[`isFixedSpacing`](/documentation/UIKit/NSCollectionLayoutSpacing/isFixed)

A Boolean value that indicates whether the space is fixed to a specific number of points.

[`isFlexibleSpacing`](/documentation/UIKit/NSCollectionLayoutSpacing/isFlexible)

A Boolean value that indicates whether the space is flexible.

## Relationships

### Conforms To

[`CVarArg`](/documentation/Swift/CVarArg)

[`Sendable`](/documentation/Swift/Sendable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)