Sitemap
DevTechie

DevTechie.com is all about sharing knowledge by practical means. We focus on solving real world challenges via code.

Member-only story

Angular Gradient in SwiftUI

--

Press enter or click to view image in full size
Photo by Luke Chesser on Unsplash

AngularGradient view in SwiftUI was introduced with iOS 13 and is used to draw an angular gradient. This view conforms to ShapeStyle protocol.

For the simplest initializer AngularGradient takes colors as a parameter along with UnitPoint for the location of center as shown below:

struct AngularGradientExample: View {
let colors = [Color.blue, .purple, .cyan, .teal, .green, .orange, .pink, .red]
var body: some View {
AngularGradient(colors: colors, center: .center)
.edgesIgnoringSafeArea(.all)
}
}

We can move center by changing the value for center.

struct AngularGradientExample: View {
let colors = [Color.blue, .purple, .cyan, .teal, .green, .orange, .pink, .red]
var body: some View {
AngularGradient(colors: colors, center: .topLeading)
.edgesIgnoringSafeArea(.all)
}
}

Instead of typing all enum values for UnitPoint, we will animate between them.

struct…

--

--

DevTechie
DevTechie

Published in DevTechie

DevTechie.com is all about sharing knowledge by practical means. We focus on solving real world challenges via code.