Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a conical gradient in iOS using Core Graphics / Quartz 2D?

How can I draw such a conical gradient in iOS using Core Graphics / Quartz 2D API?

Conical Gradient Sample
(source: ods.com.ua)

like image 629
Benji Mizrahi Avatar asked Mar 21 '11 14:03

Benji Mizrahi


1 Answers

If anyone is still looking for a solution, Apple finally introduced .conic gradient type in iOS 12. Perfect for masking to create circular progress bar with gradient.

Example:

let gradientLayer = CAGradientLayer()
gradientLayer.startPoint = CGPoint(x: 0.5, y: 0.5)
gradientLayer.endPoint = CGPoint(x: 0.5, y: 0)
gradientLayer.type = .conic
gradientLayer.colors = [UIColor.red.cgColor, UIColor.orange.cgColor, UIColor.green.cgColor]
gradientLayer.frame = bounds

conic_gradient

like image 189
Michał Kwiecień Avatar answered Oct 13 '22 10:10

Michał Kwiecień