Skip to content

Instantly share code, notes, and snippets.

@lucianoschillagi
Last active November 9, 2023 20:21
Show Gist options
  • Save lucianoschillagi/6343c17fbd061e20c9b14e75012b6b84 to your computer and use it in GitHub Desktop.
Save lucianoschillagi/6343c17fbd061e20c9b14e75012b6b84 to your computer and use it in GitHub Desktop.
Opposite Color with Color Picker
import SwiftUI
struct ColorPickerView: View {
@State private var selectedColor = Color.blue
var body: some View {
VStack {
ColorPicker("", selection: $selectedColor).padding(.bottom)
ColorRectangle(selectedColor: $selectedColor)
ColorRectangle(selectedColor: $selectedColor).colorInvert()
}.padding()
}
}
struct ColorRectangle: View {
@Binding var selectedColor: Color
var body: some View {
Rectangle()
.foregroundColor(selectedColor)
.frame(width: 300, height: 300)
.cornerRadius(10)
.overlay {
Text("Color").font(.system(size: 60)).foregroundColor(selectedColor).bold().colorInvert().fontDesign(.rounded)
}.padding(.bottom)
}
}
#Preview {
ColorPickerView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment