Created
August 3, 2022 15:21
-
-
Save gromwel/631c7428b31a6522c626b8e0f9c40852 to your computer and use it in GitHub Desktop.
SwiftUI Gradient Animation
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
struct ContentView: View { | |
@State private var animateGradient = false | |
var body: some View { | |
ZStack { | |
LinearGradient( | |
colors: [.red, .purple], | |
startPoint: animateGradient ? .topLeading : .bottomLeading, | |
endPoint: animateGradient ? .bottomTrailing : .topTrailing | |
) | |
.hueRotation(.degrees(animateGradient ? 0 : 360)) | |
// .brightness(animateGradient ? 0 : 0.1) | |
// .saturation(animateGradient ? 0.9 : 1) | |
.animation(.linear(duration: 10).repeatForever(), value: animateGradient) | |
Text("hello") | |
.foregroundColor(.white) | |
.font(.largeTitle) | |
.fontWeight(.black) | |
} | |
.frame(width: 300, height: 300) | |
.onAppear { animateGradient.toggle() } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment