Filling a path with a gradient on iOS

后端 未结 2 1885
小蘑菇
小蘑菇 2021-02-09 00:36

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 wit

2条回答
  •  执念已碎
    2021-02-09 01:14

    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];

提交回复
热议问题