Instance Method


Sets the preferred color scheme for this presentation.


func preferredColorScheme(_ colorScheme: ColorScheme?) -> some View



The color scheme for this view.

Return Value

A view that wraps this view and sets the color scheme.


The color scheme applies to the nearest enclosing presentation, such as a popover or window. Views may read the color scheme using the colorScheme environment value.

In the example below the presentation containing the VStack has its color scheme set to ColorScheme.dark:

VStack {
    Button(action: {}) {
        Text(" Button")
    HStack {
        Text(" Slider").accentColor(
        Slider(value: $sliderValue, in: -100...100, step: 0.1)

See Also

Adopting View Color Schemes

func colorScheme(ColorScheme) -> View

Sets the view’s color scheme.

enum ColorScheme

The possible types of color schemes, like Dark Mode.

struct PreferredColorSchemeKey

A key for specifying the preferred color scheme.