Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SarahAlsharif/963247b1a596270c85a6ffca64b1b6d7 to your computer and use it in GitHub Desktop.
Save SarahAlsharif/963247b1a596270c85a6ffca64b1b6d7 to your computer and use it in GitHub Desktop.
struct NeuButtonBackgroundView : View {
let cornerRadius : CGFloat
@Binding var opacity : CGFloat
@Binding var opacityOp : CGFloat
@Binding var shadowRadiusXY : CGFloat
var body: some View {
ZStack {
//Button shape and color
RoundedRectangle(cornerRadius: cornerRadius)
.fill(Color(Colors.mainColor))
//Button's dark edge (top left)
RoundedRectangle(cornerRadius: cornerRadius)
.stroke(Color(Colors.darkShadow).opacity(opacityOp), lineWidth: 2)
.mask(RoundedRectangle(cornerRadius: cornerRadius).fill(LinearGradient(colors:[Color(Colors.darkShadow).opacity(opacityOp), Color.clear], startPoint: .top, endPoint: .bottom)))
//Button's inner dark shadow (top left)
RoundedRectangle(cornerRadius: cornerRadius)
.stroke(Color(Colors.darkShadow), lineWidth: 2)
.blur(radius: 3)
.offset(x: 1, y: 1)
.mask(RoundedRectangle(cornerRadius: cornerRadius).fill(LinearGradient(colors: [Color(Colors.darkShadow).opacity(opacityOp), Color.clear], startPoint: .top, endPoint: .bottom)))
//Button's inner light edge (bottom right)
RoundedRectangle(cornerRadius: cornerRadius)
.stroke(Color(Colors.lightShadow).opacity(opacityOp), lineWidth: 2)
.mask(RoundedRectangle(cornerRadius: cornerRadius).fill(LinearGradient(colors: [Color.clear, Color(Colors.lightShadow).opacity(opacityOp)], startPoint: .top, endPoint: .bottom)))
}
//Button's outer light shadow (top left)
.shadow(color: Color(Colors.lightShadow).opacity(opacity), radius: shadowRadiusXY, x: -shadowRadiusXY, y: -shadowRadiusXY)
//Button's outer dark shadow (bottom right)
.shadow(color: Color(Colors.darkShadow).opacity(opacity), radius: shadowRadiusXY, x: shadowRadiusXY, y: shadowRadiusXY)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment