Declaration
Initializers
2 SwiftUI initializers back <ColorPicker>. The props you pass pick one.
<ColorPicker
selection: Binding<SwiftUI.Color>
supportsOpacity?: boolean
>
children?: ReactNode
</ColorPicker>nonisolated init(
selection: Binding<Color>,
supportsOpacity: Bool = true,
@ContentBuilder label: () -> Label
)selection*Binding<SwiftUI.Color>A
Bindingto the variable that displays the selected[Color](/docs/components/color).supportsOpacitybooleanA Boolean value that indicates whether the color picker allows adjusting the selected color's opacity; the default is
true.Default
`true`childrenReactNodeContent. Strings become
Text; React Native views are laid out by Yoga and placed by SwiftUI.Swift
label: () -> Label
Also takes the common view props: modifiers, style and testID.
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)
}
}
}From Apple’s SwiftUI documentation. Code samples there are Swift.
Relationships
Conforms to
- View
See also
More in Controls.
- ButtonA control that initiates an action.
- DatePickerA control for selecting an absolute date.
- DisclosureGroupA view that shows or hides another content view, based on the state of a disclosure control.
- MultiDatePickerA control for picking multiple dates.
- OutlineGroupA structure that computes views and disclosure groups on demand from an underlying collection of tree-structured, identified data.
- PasteButtonA system button that reads items from the pasteboard and delivers it to a closure.
- PickerA control for selecting from a set of mutually exclusive values.
- SecureFieldA control into which people securely enter private text.
- SliderA control for selecting a value from a bounded linear range of values.
- StepperA control that performs increment and decrement actions.
- SubscriptionViewA view that subscribes to a publisher with an action.
- TableA container that presents rows of data arranged in one or more columns, optionally providing the ability to select one or more members.