Color gradient of a line with CoreGraphics
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开发者_StackOverflow社区 gradient?
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.
精彩评论