Skip to content

Instantly share code, notes, and snippets.

@zeeshankhan
Forked from jordansinger/Gradient.swift
Created July 18, 2020 04:01
Show Gist options
  • Save zeeshankhan/f82c24007d29f181442ca858d5e984c5 to your computer and use it in GitHub Desktop.
Save zeeshankhan/f82c24007d29f181442ca858d5e984c5 to your computer and use it in GitHub Desktop.
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
@State var gradientAngle: Double = 0
var colors = [
Color(UIColor.systemRed),
Color(UIColor.systemOrange),
Color(UIColor.systemYellow),
Color(UIColor.systemGreen),
Color(UIColor.systemBlue),
Color(UIColor.systemIndigo),
Color(UIColor.systemPurple)
]
var body: some View {
ZStack {
Rectangle()
.fill(
AngularGradient(gradient: Gradient(colors: colors), center: .center, angle: .degrees(gradientAngle))
)
.overlay(
Blur(style: .systemThinMaterial)
)
}
.onAppear {
withAnimation(Animation.linear(duration: 12).repeatForever(autoreverses: false)) {
self.gradientAngle = 360
}
}
}
}
struct Blur: UIViewRepresentable {
var style: UIBlurEffect.Style
func makeUIView(context: Context) -> UIVisualEffectView {
return UIVisualEffectView(effect: UIBlurEffect(style: style))
}
func updateUIView(_ uiView: UIVisualEffectView, context: Context) {
uiView.effect = UIBlurEffect(style: style)
}
}
PlaygroundPage.current.setLiveView(ContentView())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment