Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created January 24, 2021 16:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/efa53842e320f9648bf17ef6c2e82038 to your computer and use it in GitHub Desktop.
Save sturdysturge/efa53842e320f9648bf17ef6c2e82038 to your computer and use it in GitHub Desktop.
struct AquaButtonStyle: ButtonStyle {
func makeBody(configuration: Self.Configuration) -> some View {
AquaButton(configuration: configuration)
}
}
struct AquaButton: View {
let configuration: AquaButtonStyle.Configuration
let mainGradient = Gradient(colors: [Color(white: 1, opacity: 0.9),
Color(white: 1, opacity: 0)])
let highlightGradient = Gradient(colors: [.white,
Color(white: 1, opacity: 0.7),
Color(white: 1, opacity: 0.3)])
var body: some View {
GeometryReader { geometry in let highlightHeight = geometry.size.height * 0.3
ZStack {
//Main colour (foregroundColor of the Button)
Capsule()
//Gradient on top of the main colour
LinearGradient(gradient: mainGradient, startPoint: .bottom, endPoint: .top)
Group {//Top highlight
LinearGradient(gradient: highlightGradient, startPoint: .top, endPoint: .bottom)
.frame(height: highlightHeight)
.clipShape(Capsule())
.padding(.horizontal, 5)
}
.frame(maxHeight: .infinity, alignment: .top)
//The outline for the button
Capsule()
.stroke(lineWidth: 2)
.foregroundColor(.black)
//The generic Label, most likely a Text with the title of the Button
configuration.label
.foregroundColor(.black)
.font(.system(size: 10, weight: .bold, design: .default))
}
//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