Contents

ColorPicker

A control used to select a color from the system color picker UI.

Declaration

struct ColorPicker<Label> where Label : View

Overview

The color picker shows the currently selected color and displays the larger system color picker that allows people to select a new color.

By default color picker supports colors with opacity; to disable opacity support, set the supportsOpacity parameter to false. In this mode the color picker won’t show controls for adjusting the opacity of the selected color, and strips out opacity from any color set programmatically or selected from the user’s system favorites.

You use ColorPicker by embedding it inside a view hierarchy and initializing it with a title string and a Binding to a Color:

struct FormattingControls: View {
    @State private var bgColor =
        Color(.sRGB, red: 0.98, green: 0.9, blue: 0.2)

    var body: some View {
        VStack {
            ColorPicker("Alignment Guides", selection: $bgColor)
        }
    }
}

Topics

Creating a color picker