Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created January 26, 2021 13:51
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 sturdysturge/6d4cd918be03cbbc23aecb4d3392ca1b to your computer and use it in GitHub Desktop.
Save sturdysturge/6d4cd918be03cbbc23aecb4d3392ca1b to your computer and use it in GitHub Desktop.
struct AquaButtonStyle: ButtonStyle {
func makeBody(configuration: Self.Configuration) -> some View {
AquaButton()
}
}
struct AquaButton: View {
var body: some View {
GeometryReader { geometry in
let topHighlightHeight = geometry.size.height * 0.3
let bottomHighlightOffset = geometry.size.height * 0.6
ZStack {
Capsule() //Behind highlight
.foregroundColor(.white)
.offset(y: 1.5)
Group {
//Main colour (foregroundColor of the Button)
Capsule()
//Gradient on top of the main colour
Capsule() //Bottom highlight
.foregroundColor(.white)
.offset(y: bottomHighlightOffset)
.blur(radius: 3)
Group {
Capsule() //Top highlight
.frame(height: topHighlightHeight)
.foregroundColor(Color.white)
.offset(y: 1)
.blur(radius: 2)
.padding(.horizontal, 5)
}
.frame(maxHeight: .infinity, alignment: .top)
//The outline for the button
Capsule().stroke(Color.black, lineWidth: 3.5)
}
//Make sure none of the layers go outside the shape
.clipShape(Capsule())
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment