Filling a path with a gradient on iOS

cagradientlayer, ios, uibezierpath

Solution

What you want is a mask. CAGradientlayer has a -setMask method that can clip it to the bounds of your shape like so:

`[gradientLayer setMask:shapeLayer];`

Problem

On a `CAShapeLayer`, I've drawn a closed `UIBezierPath`. I can fill this shape by setting the `fillColor`, however I want to fill the shape with a gradient. How can I set up the `CAGradientLayer`so it clips to the shape outlined by the bezier path?

Original source