<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "DeveloperToolsSupport",
  "identifier" : "/documentation/DeveloperToolsSupport/PreviewLayout",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration",
  "symbol" : {
    "kind" : "Enumeration",
    "modules" : [
      "DeveloperToolsSupport"
    ],
    "preciseIdentifier" : "s:21DeveloperToolsSupport13PreviewLayoutO"
  },
  "title" : "PreviewLayout"
}
-->

# PreviewLayout

A size constraint for a preview.

```
enum PreviewLayout
```

## Overview

Customize the layout of a preview that you define using the
<doc://com.apple.documentation/documentation/SwiftUI/PreviewProvider>
protocol by providing one of the preview layout values to the
<doc://com.apple.documentation/documentation/SwiftUI/View/previewLayout(_:)>
view modifier. For example, you can tell the preview to take up only the
amount of space that the view requires with [`PreviewLayout.sizeThatFits`](/documentation/DeveloperToolsSupport/PreviewLayout/sizeThatFits):

```
struct CircleImage_Previews: PreviewProvider {
    static var previews: some View {
        CircleImage()
            .previewLayout(.sizeThatFits)
    }
}
```

> Note: When you migrate away from preview providers and to preview macros,
> you specify layout using one of the ``doc://com.apple.DeveloperToolsSupport/documentation/DeveloperToolsSupport/PreviewTrait`` layout
> values with a macro that takes traits, like
> <doc://com.apple.documentation/documentation/SwiftUI/Preview(_:traits:_:body:)>.

## Topics

### Getting a layout

[`case device`](/documentation/DeveloperToolsSupport/PreviewLayout/device)

Center the preview in a container the size of the device on which the
preview is running.

[`case fixed(width: CGFloat, height: CGFloat)`](/documentation/DeveloperToolsSupport/PreviewLayout/fixed(width:height:))

Center the preview in a fixed size container with the given dimensions.

[`case fixed3D(width: CGFloat, height: CGFloat, depth: CGFloat)`](/documentation/DeveloperToolsSupport/PreviewLayout/fixed3D(width:height:depth:))

Centers the preview in a fixed-size, 3D container.

[`case sizeThatFits`](/documentation/DeveloperToolsSupport/PreviewLayout/sizeThatFits)

Fit the container to the size of the preview when offered the size of
the device that the preview is running on.

## Relationships

### Conforms To

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

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

---

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)