Created
July 16, 2020 16:13
-
-
Save gtzsb/34ed19ef91c618276995dffa224cff46 to your computer and use it in GitHub Desktop.
SwiftUI Rotating Gradient
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
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()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tysm!