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

后端 未结 4 1088
不思量自难忘°
不思量自难忘° 2020-12-10 05:23

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


(source: ods.com.ua)

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-10 06:06

    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
    

提交回复
热议问题