-
-
Save sturdysturge/37de91dd1fccca77ee96bc7104670e89 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
| import SwiftUI | |
| struct ContentView: View { | |
| static let defaultColour = Color.blue | |
| static let pressedColour = Color.red | |
| static let completeColour = Color.green | |
| @State var buttonColour = Self.defaultColour | |
| var body: some View { | |
| VStack { | |
| Text("Press") | |
| .font(.largeTitle) | |
| .foregroundColor(.white) | |
| .padding() | |
| .background(buttonColour) | |
| .cornerRadius(15) | |
| .onLongPressGesture(minimumDuration: 3, maximumDistance: 150) { | |
| buttonColour = Self.completeColour | |
| } onPressingChanged: { pressed in | |
| buttonColour = pressed ? Self.pressedColour : Self.defaultColour | |
| } | |
| Button("Reset") { buttonColour = Self.defaultColour } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment