Skip to content

Instantly share code, notes, and snippets.

@Priva28
Created January 18, 2023 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Priva28/637f3537bfc2390269508588c3a09473 to your computer and use it in GitHub Desktop.
Save Priva28/637f3537bfc2390269508588c3a09473 to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
var body: some View {
Button {
} label: {
Text("Press this button")
.foregroundColor(.white)
.padding(12)
.background(
RoundedRectangle(cornerRadius: 12)
)
}
.buttonStyle(ScaleButtonStyle())
}
}
public struct ScaleButtonStyle: ButtonStyle {
public init() {}
public func makeBody(configuration: Configuration) -> some View {
configuration.label
.scaleEffect(configuration.isPressed ? 0.97 : 1)
.offset(y: configuration.isPressed ? 2 : 0)
.opacity(configuration.isPressed ? 0.94 : 1)
.animation(.easeInOut(duration: 0.1), value: configuration.isPressed)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment