1

I am drawing shape using CGPath and after drawing it,adding to CAShapeLayer.I am getting frame using CGPathGetPathBoundingBox() (this frame will set to CAShapeLayer) but it is in rectangle form while my path is in different form.So when i am trying to give gradient colour ,it is showing too much gradient in some portion of path and in some portion you cant see anything.basically gradient color is setting on frame of CAShapeLayer.So is there any way to set gradient color to CGPath?Please help me.Thanking you.Hint will also be appreciated.

h999
  • 395
  • 1
  • 5
  • 21

1 Answers1

1

This answer shows you how to fill a path with a gradient using both Core Graphics and using layers.

In short what you need to do for your layers is to mask the gradient layer with a shape layer. If you are using strokes or shadows you also need an outer shape layer (not masked).

Community
  • 1
  • 1
David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205