Skip to content

Instantly share code, notes, and snippets.

@LemonSpike
Created April 30, 2021 19:00
Show Gist options
  • Save LemonSpike/6491bbf9f52acc748ad59a60c2e25132 to your computer and use it in GitHub Desktop.
Save LemonSpike/6491bbf9f52acc748ad59a60c2e25132 to your computer and use it in GitHub Desktop.
Example code for creating gradients with CAGradientLayer
let view = UIView()
view.backgroundColor = .white
let gradient = CAGradientLayer()
gradient.frame = view.bounds
gradient.colors = [UIColor.black.cgColor, UIColor.white.cgColor]
gradient.locations = [0, 1]
gradient.startPoint = CGPoint(x: 1, y: 1)
gradient.endPoint = CGPoint(x: 0, y: 0)
view.layer.masksToBounds = true
view.layer.insertSublayer(gradient, at: 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment