我该如何使用Core Graphics / Quartz 2D API在iOS中绘制这样一个圆锥形渐变?请参考以下图像:
(图片来源: ods.com.ua)
![Conical Gradient Sample](https://istack.dev59.com/ATlVZ.gif)
如果有人仍在寻找解决方案,苹果最终在iOS 12中引入了.conic
渐变类型。非常适合用于掩盖以创建带渐变的圆形进度条。
示例:
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
对于这种渐变样式,Quartz 没有相应的函数。除非你准备深入研究其背后的数学原理,否则建议使用预制图像。如果你只需要透明度掩码,那么这并不是问题。