Enumeration¶
PreviewLayout¶
The size constraint for a preview.¶
Declaration¶
enum PreviewLayout
Overview¶
Use this enumeration along with the previewLayout(_:) view modifier to change the way a view is displayed in a preview.
This enumeration has 3 different cases:
- device: Center the preview in the specified device.
- sizeThatFits: Fix the preview to the view size.
- fixed: Center the preview in a fixed size container.
In the following example, we fit a preview box to the text view.
struct ContentView: View {
var body: some View {
Text("➡️This box fits me snugly⬅️")
}
}
struct ContentView\_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.previewLayout(.sizeThatFits)
}
}

Availability¶
iOS 13.0+
macOS 10.15+
tvOS 13.0+
watchOS 6.0+
Topics¶
Case¶
device Center the preview in a container the size of the device on which the preview is running.
fixed Center the preview in a fixed size container.
sizeThatFits Fit the container to the size of the preview when offered the size of the device on which the preview is running.