Member-only story
Gradients in Swift
How gradual is this?
1 min readJul 23, 2019
To add gradient effects to views you deal with the sublayer of the UIView, rather than the UIView itself. But how does this work when we want to add gradients and us the mysterious gradient Locations.
Prerequisites:
- Some knowledge of CoreGraphics would be useful
Terminology
CAGradientLayer: A layer that draws a colour gradient over its background colour
Locations: The location where a gradient stopsBackground
Locations
Locations are where gradient stop.
For example, in the first view above the red gradient begins at 0 (the top), and ends at 0.5 (the center).
1 is at the bottom of the relevant view.
Sample code to achieve the gradients above:
A GitHub link for this project:
https://github.com/stevencurtis/SwiftCoding/tree/master/GradientsInSwift
Want to get in contact? Try the link here: