Last active
November 9, 2023 20:21
-
-
Save lucianoschillagi/6343c17fbd061e20c9b14e75012b6b84 to your computer and use it in GitHub Desktop.
Opposite Color with Color Picker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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