Contents

presentationBackground(alignment:content:)

Sets the presentation background of the enclosing sheet to a custom view.

Declaration

nonisolated func presentationBackground<V>(alignment: Alignment = .center, @ViewBuilder content: () -> V) -> some View where V : View

Parameters

  • alignment:

    The alignment that the modifier uses to position the implicit Zstack that groups the background views. The default is Center.

  • content:

    The view to use as the background of the presentation.

Discussion

The following example uses a yellow view as the sheet background:

struct ContentView: View {
    @State private var showSettings = false

    var body: some View {
        Button("View Settings") {
            showSettings = true
        }
        .sheet(isPresented: $showSettings) {
            SettingsView()
                .presentationBackground {
                    Color.yellow
                }
        }
    }
}

The presentationBackground(alignment:content:) modifier differs from the background(alignment:content:) modifier in several key ways. A presentation background:

  • Automatically fills the entire presentation.

  • Allows views behind the presentation to show through translucent areas of the content on supported platforms.

See Also

Styling a sheet and its background