Created
June 29, 2022 09:09
-
-
Save burhanaras/ad10ea037a3bc7d297ba9a5872771bc6 to your computer and use it in GitHub Desktop.
This file contains 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 LinearGradient { | |
static func addLinearGradient( | |
colors: [Color] = [ | |
Color(UIColor.alphaVariant40.withAlphaComponent(0.2)), | |
Color(UIColor.alphaVariant39) | |
]) -> LinearGradient { | |
return LinearGradient( | |
gradient: Gradient(colors: colors), | |
startPoint: .bottomLeading, | |
endPoint: .topTrailing | |
) | |
} | |
} | |
struct GradientBorder: ViewModifier { | |
let cornerRadius: CGFloat | |
func body(content: Content) -> some View { | |
content | |
.overlay( | |
RoundedRectangle(cornerRadius: cornerRadius) | |
.stroke( | |
LinearGradient.addLinearGradient(), | |
lineWidth: CGFloat(2.0) | |
) | |
) | |
} | |
} | |
extension View { | |
func gradientBorder(cornerRadius: CGFloat = CGFloat(12.0)) -> some View { | |
modifier(GradientBorder(cornerRadius: cornerRadius)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment