The Library Bookmarks · Notes · Snippets

← Back to the front page Filed

Animated background gradient

swift

LinearGradient(colors: [.purple, .yellow], startPoint: animateGradient ? .topLeading : .bottomLeading, endPoint: animateGradient ? .bottomTrailing : .topTrailing)
                .ignoresSafeArea()
                .onAppear {
                    withAnimation(.linear(duration: 10.0).repeatForever(autoreverses: true)) {
                        animateGradient.toggle()
                    }
                }

■