I've a custom shape drawing using coregraphics and i want to add a drop shadow and a gradient to it also. I've been trying and searching a lot of informations on how to combine and do this, but i can't get it to work. I'm able to draw only one either. Anyone doing this already or know how to do this? Thank you.
Asked
Active
Viewed 1,413 times
1
-
possible duplicate of http://stackoverflow.com/questions/2263273/cgcontextsetshadow-produces-no-results – Peter Hosey Apr 05 '10 at 11:49
1 Answers
3
Quartz only applies shadows to fills and strokes. Drawing a gradient does not count as a fill.
Fill with a solid color (to draw the shadow), then draw the gradient in the same area.

Peter Hosey
- 95,783
- 15
- 211
- 370
-
so just to clarify... 1. draw a shape with solid color fill 2. save the state 3. draw the shadow 4. restore the state 5. draw the same shape as point 1 but with the gradient is this correct? so i need to draw the shape 3 times right? – Luca Apr 05 '10 at 12:42
-
There is no way to “draw the shadow”. Quartz draws the shadow for you when you fill or stroke. So, set the shadow, then fill (with a solid color) the shape, then draw the gradient over it. – Peter Hosey Apr 05 '10 at 12:54
-
Looks like you're right Peter, but I think it might be an oversight, albeit a difficult one to fix. Images and text draw shadows, for example, as do transparency layers and CGLayers. I cannot think of any non-shading based drawing that _doesn't_ produce a shadow. The header just says "After a shadow is specified, all objects drawn subsequently will be shadowed." – Ken Apr 07 '10 at 08:29