让我们说我有一个图像(半圆形),颜色从绿色到黄色到红色。如何使用CoreGraphics / Quartz以编程方式动态剪辑和填充给定百分比的图像?
答案 0 :(得分:1)
您可以将CALayer与自定义蒙版一起使用。
掩码将是一个CAShapeLayer,其路径定义了指定的百分比。
CALayer *guageLayer = //your CALayer, could be the backing view
CAShapeLayer *guageMask = [[CAShapeLayer alloc] init];
guageMask.path = [self _pathForCurrentGuage]; //bezier path based on your current percentage
guageLayer.mask = guageMask;