< How to create multi-line editable text with TextEditor | How to show progress on a task using ProgressView > |
Updated for Xcode 14.2
SwiftUI has a native ColorPicker
control that allows the user to select a color. To use it, first create a Color
property that can be changed using @State
or similar, then
struct ContentView: View {
@State private var bgColor = Color.red
var body: some View {
VStack {
ColorPicker("Set the background color", selection: $bgColor)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(bgColor)
}
}
Download this as an Xcode project
By default ColorPicker
supports opacity in the color selection, but you can disable that with a slightly different initializer:
struct ContentView: View {
@State private var bgColor = Color.red
var body: some View {
VStack {
ColorPicker("Set the background color", selection: $bgColor, supportsOpacity: false)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(bgColor)
}
}
Download this as an Xcode project
SPONSORED Thorough mobile testing hasn’t been efficient testing. With Waldo Sessions, it can be! Test early, test often, test directly in your browser and share the replay with your team.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.