【问题标题】:How to make a conical gradient in iOS using Core Graphics / Quartz 2D?如何使用 Core Graphics / Quartz 2D 在 iOS 中制作锥形渐变?
【发布时间】:2011-07-19 18:01:41
【问题描述】:

如何在 iOS 中使用 Core Graphics / Quartz 2D API 绘制这样的锥形渐变?


(来源:ods.com.ua

【问题讨论】:

    标签: ios core-graphics gradient radial-gradients


    【解决方案1】:

    如果有人还在寻找解决方案,Apple 终于在 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
    

    【讨论】:

    • 作为 iOS 12 中可用的 .conic 我们如何在以前的版本(iOS 11)中实现这一点
    • 您必须寻找此问题中提出的其他解决方案。
    【解决方案2】:

    最近我为此制作了一个自定义的 CALayer 类:AngleGradientLayer

    它没有经过性能测试,所以要小心。

    【讨论】:

      【解决方案3】:

      我想要纯 Swift 解决方案,这对我来说也是一项具有挑战性的任务。

      最后,我写了AEConicalGradient,它以有趣的方式做到了这一点(通过使用一个圆圈并在中心绘制不同颜色的线条)。

      【讨论】:

        【解决方案4】:

        这种渐变风格没有 Quartz 功能。除非您准备好深入研究其背后的数学,否则我建议您为此使用预制图像。如果您只需要它用于不透明蒙版,这不是问题。

        【讨论】:

        • 如果非要支持
        • 他们在哪里将它添加到 CoreGraphcs?我只在 CALayer 中看到 .conic,但 CoreGraphics 不会仅渲染 .conic 径向和线性。
        猜你喜欢
        • 1970-01-01
        • 2011-02-19
        • 1970-01-01
        • 1970-01-01
        • 2010-12-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多