Skip to content

Instantly share code, notes, and snippets.

@gabrieltheodoropoulos
Created November 5, 2020 15:12
Show Gist options
  • Save gabrieltheodoropoulos/953f4875ef3afbee1cc2e469a08053ea to your computer and use it in GitHub Desktop.
Save gabrieltheodoropoulos/953f4875ef3afbee1cc2e469a08053ea to your computer and use it in GitHub Desktop.
SwiftUI button implementation with image that is changed on press, without default highlighting
Image(!isPressed ? "imageNormal" : "imagePressed")
.resizable()
.overlay(
GeometryReader { geometry in
Button(action: { }, label: {
Text("")
.frame(width: geometry.size.width, height: geometry.size.height)
.contentShape(Rectangle())
})
.buttonStyle(PlainButtonStyle())
.pressAction {
isPressed = true
} onRelease: {
isPressed = false
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment