views:

49

answers:

1

I need a line that changes color along the path (which could be approximated by a linear gradient in one direction, if that is easier).

Is it possible to draw the path of a CAShapeLayer so that it has a color gradient?

+1  A: 

You might be able to use a CAShapeLayer as a mask for a CAGradientLayer by setting it to the CAGradientLayer's mask property. This might give you the gradient along the line you are seeking.

Otherwise, follow the code example from this answer to draw a path using Core Graphics, clip to it using CGContextClip(), and then draw a gradient which will only appear within the drawn path.

Brad Larson