Skip to content

Instantly share code, notes, and snippets.

@filimo
Created January 27, 2020 19:42
Show Gist options
  • Save filimo/efdd3b65191a172c6bd28583fb61a3ad to your computer and use it in GitHub Desktop.
Save filimo/efdd3b65191a172c6bd28583fb61a3ad to your computer and use it in GitHub Desktop.
import SwiftUI
struct ScaleButtonStyle: ButtonStyle {
public func makeBody(configuration: Configuration) -> some View {
print(configuration.isPressed)
return configuration.label
.frame(width: 200, height: 200)
.scaleEffect(configuration.isPressed ? 0.9 : 1)
.animation(.easeInOut)
}
}
struct SimpleScaleButtonStyle: ButtonStyle {
public func makeBody(configuration: Configuration) -> some View {
configuration.label.scaleEffect(configuration.isPressed ? 0.9 : 1.0)
}
}
struct SimpleCard: View {
var body: some View {
ZStack {
Button(action: {
}) {
Rectangle()
}.buttonStyle(ScaleButtonStyle())
Button(action: {
}) {
Rectangle()
.foregroundColor(Color.red)
.frame(width: 50, height: 50)
}.buttonStyle(SimpleScaleButtonStyle())
}
}
}
struct SimpleCard_Previews: PreviewProvider {
static var previews: some View {
SimpleCard()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment