<!--
{
  "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

[`class func fixed(CGFloat) -> Self`](/documentation/UIKit/NSCollectionLayoutSpacing/fixed(_:))

Creates a space equivalent to the specified number of points.

[`class func flexible(CGFloat) -> Self`](/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

[`var spacing: CGFloat`](/documentation/UIKit/NSCollectionLayoutSpacing/spacing)

The floating-point value of the space.

### Getting the spacing type

[`var isFixed: Bool`](/documentation/UIKit/NSCollectionLayoutSpacing/isFixed)

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

[`var isFlexible: Bool`](/documentation/UIKit/NSCollectionLayoutSpacing/isFlexible)

A Boolean value that indicates whether the space is flexible.

## Relationships

### Conforms To

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

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

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

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

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

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

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

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

### 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)