Skip to content

Instantly share code, notes, and snippets.

@burhanaras
Created June 29, 2022 09:09
Show Gist options
  • Save burhanaras/ad10ea037a3bc7d297ba9a5872771bc6 to your computer and use it in GitHub Desktop.
Save burhanaras/ad10ea037a3bc7d297ba9a5872771bc6 to your computer and use it in GitHub Desktop.
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