Created
November 23, 2019 16:42
-
-
Save a-v-ershov/3e7ee3c176145c2c94d2d7bc0f7ae6d3 to your computer and use it in GitHub Desktop.
TapGesture Example
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 TapGestureExample: View { | |
@State var rectangleColor = Color(.green) | |
var body: some View { | |
// TapGesture creation | |
let tapGesture = TapGesture() | |
// Change color when tap ended | |
.onEnded { _ in | |
if self.rectangleColor == .red { | |
self.rectangleColor = .green | |
} else { | |
self.rectangleColor = .red | |
} | |
} | |
return Rectangle() | |
// Change color | |
.foregroundColor(rectangleColor) | |
.cornerRadius(40) | |
.frame(width: 200, height: 100, alignment: .center) | |
// Add the tapGesture to this view | |
.gesture(tapGesture) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment