Last active
June 11, 2020 03:30
-
-
Save aheze/62a2defe8ccc1a2eb1178af85738fef4 to your computer and use it in GitHub Desktop.
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
| struct ColorView: View { | |
| @Binding var colorRectangleIsGreen: Bool | |
| var body: some View { | |
| RoundedRectangle(cornerRadius: 5) | |
| .fill(colorRectangleIsGreen ? Color.green : Color.blue) | |
| .frame(width: 100, height: 100) | |
| .padding() | |
| } | |
| } | |
| struct ContentView: View { | |
| @State var rectangleIsGreen = false | |
| var body: some View { | |
| VStack { | |
| ColorView(colorRectangleIsGreen: $rectangleIsGreen) | |
| Button(action: { | |
| self.rectangleIsGreen.toggle() | |
| }) { | |
| Text("Toggle color!") | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment