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.
Asked
Active
Viewed 3,420 times
1
-
Show the code your using and, preferably, screen shots of the result and what you want the result to be. – Wain Aug 21 '13 at 06:14
-
You haven't shown the gradient and the shape layer, these are he bits you say don't work. – Wain Aug 21 '13 at 06:57
-
updated my whole code... – h999 Aug 21 '13 at 07:01
-
It's unlikely you want to set the layer bounds. What is `gradientColorForPolygon`? – Wain Aug 21 '13 at 07:03
-
it is method to set gradient layer... – h999 Aug 21 '13 at 07:04
-
@h999 you can update your question instead of posting additional information as a comment. – David Rönnqvist Aug 21 '13 at 07:10
1 Answers
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
-
in your answer, everything is in core graphics and i need to do in core animation.can you explain one more time? – h999 Aug 21 '13 at 07:18
-
scroll down to the "For reference: the same drawing using Core Animation" part – David Rönnqvist Aug 21 '13 at 07:24