Rendering a gradient view in SwiftUI
SwiftUI has several ways of rendering gradients. A gradient can be used to fill a shape, or even fill a border.In this recipe, we will understand what types of gradients we can use with SwiftUI and how to define them.
Getting ready
Create a SwiftUI app called GradientViews.
How to do it…
SwiftUI has four different types of gradients:
- Linear gradients
- Radial gradients
- Elliptical gradients
- Angular gradients
In each one, we can define the list of colors that will smoothly transform into each other. Depending on the type of gradient, we can define some additional properties such as the direction, radius, and angles of the transformation.To explore all of them, we are going to add a Picker view to select the type of gradient we want to draw on the screen.The ContentView struct will have a Text component that shows the selected gradient. We can do this by performing the following steps:
- Let's start by adding a style, including a custom...