Skip to content

Instantly share code, notes, and snippets.

@gtzsb
Created July 16, 2020 16:13
Show Gist options
  • Save gtzsb/34ed19ef91c618276995dffa224cff46 to your computer and use it in GitHub Desktop.
Save gtzsb/34ed19ef91c618276995dffa224cff46 to your computer and use it in GitHub Desktop.
SwiftUI Rotating Gradient
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
@State var gradientAngle: Double = 0
let colors: [Color] = [
.pink,
.red,
.orange,
.yellow,
.green,
.blue,
.purple,
.pink
]
var body: some View {
ZStack {
Rectangle()
.fill(AngularGradient(gradient: Gradient(colors: colors), center: .center, angle: .degrees(gradientAngle)))
.brightness(0.2)
.saturation(0.7)
.blur(radius: 35)
}
.onAppear {
withAnimation(Animation.linear(duration: 12).repeatForever(autoreverses: false)) {
self.gradientAngle = 360
}
}
}
}
PlaygroundPage.current.setLiveView(ContentView())
@keetsta
Copy link

keetsta commented Nov 4, 2023

tysm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment