Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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