Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created March 21, 2023 19:59
Show Gist options
  • Select an option

  • Save sturdysturge/37de91dd1fccca77ee96bc7104670e89 to your computer and use it in GitHub Desktop.

Select an option

Save sturdysturge/37de91dd1fccca77ee96bc7104670e89 to your computer and use it in GitHub Desktop.
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