Created
July 16, 2020 13:17
-
-
Save jordansinger/23ea496468d64f25b2a1fb589a7e6bbb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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()) |
Tiny note that won't affect anything,
var style
can be alet
since its value doesn't change
💯💯
Very nice!
I am just curious about the use of ZStack
here, will it make any difference if I remove it ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tiny note that won't affect anything,
var style
can be alet
since its value doesn't change