To create an iridescent view, we need to declare an x
variableto animate the gradient’s endpoint and a degree
variableto animate the rotation of the view. Let’s have a timer to animate the view every five seconds:
@State var x : CGFloat = 0
@State var degree : Double = 0
let timer = Timer.publish(every: 5, on: .main, in: .common).autoconnect()
For the gradient colors, I chose the colors below that look like the typical iridescent colors. You can change the colors to the colors of your choice.
@State var gradient : [Color] = [Color(#colorLiteral(red: 0.9700688617, green: 0.8329559691, blue: 1, alpha: 1)),
Color(#colorLiteral(red: 0.8432452348, green: 0.8160916593, blue: 1, alpha: 1)), Color(#colorLiteral(red: 0.8097396214, green: 0.945347698, blue: 1, alpha: 1)), Color(#colorLiteral(red: 0.8435950414, green: 1, blue: 0.8943966345, alpha: 1))]
#ios #programming #swift #mobile-development