Skip to content

Instantly share code, notes, and snippets.

@larsaugustin
Created February 1, 2021 19:41
Show Gist options
  • Save larsaugustin/c16231783cc76e528f4e114b66822b0d to your computer and use it in GitHub Desktop.
Save larsaugustin/c16231783cc76e528f4e114b66822b0d to your computer and use it in GitHub Desktop.
SwiftUI Inner Shadow
extension View {
@ViewBuilder func innerShadow<ShapeType: Shape>(_ shape: ShapeType, color: Color, radius: CGFloat = 10, spread: CGFloat = 4, x: CGFloat = 0, y: CGFloat = 0) -> some View {
self
.overlay(
shape.stroke(Color.clear, lineWidth: spread * 2)
.shadow(color: color, radius: radius, x: x, y: y)
)
.clipShape(shape)
}
}
RoundedRectangle(cornerRadius: 5)
// other modifiers
.innerShadow(RoundedRectangle(cornerRadius: 5), color: Color.black.opacity(0.2))
// other modifiers (like shadows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment