Skip to content

Instantly share code, notes, and snippets.

@gromwel
Created August 3, 2022 15:21
Show Gist options
  • Save gromwel/631c7428b31a6522c626b8e0f9c40852 to your computer and use it in GitHub Desktop.
Save gromwel/631c7428b31a6522c626b8e0f9c40852 to your computer and use it in GitHub Desktop.
SwiftUI Gradient Animation
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