< How to create multi-line editable text with TextEditor | How to show progress on a task using ProgressView > |
Updated for Xcode 12.5
New in iOS 14
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)
}
}
By default ColorPicker
support 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)
}
}
SPONSORED ViRE offers discoverable way of working with regex. It provides really readable regex experience, code complete & cheat sheet, unit tests, powerful replace system, step-by-step search & replace, regex visual scheme, regex history & playground. ViRE is available on Mac & iPad.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.