Created
February 1, 2021 19:41
-
-
Save larsaugustin/c16231783cc76e528f4e114b66822b0d to your computer and use it in GitHub Desktop.
SwiftUI Inner Shadow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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