Apply a shadow at both sides of a UIBezierPath

core-graphics, drawing, ios, uibezierpath

Solution

If you want to use `CGContextSetShadowwithColor()` then you will need to change the way to draw your bezierpath to the view so that you draw the `CGPath` representation to the `CGContext`. An example is below:

UIBezierPath *path;     // this is your path as before
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextAddPath(context, path.CGPath);
CGContextSetLineWidth(context, 2.0);
CGContextSetBlendMode(context, path.blendMode);
CGContextSetShadowWithColor(context, CGSizeMake(1.0, 1.0), 2.0, [UIColor blackColor].CGColor);
CGContextStrokePath(context);

Another way you could do this is to create a new `CAShapeLayer` and draw you path to that by setting it as the path property. This will easily allow you to add a shadow that will only shadow your path.

Problem

I'm currently drawing on the screen. I get smooth lines, I can change the color of my drawings. But I can't find how to apply a shadow to that line. To draw it, I use : ``` [path strokeWithBlendMode:[path blendMode] alpha:1.0]; ``` I saw that I could use `CGContextSetShadowWithColor()` but even though, I'm not sure how to use it since here's what's said in the CGPath reference for `strokeWithBlendMode`: This method automatically saves the current graphics state prior to drawing and restores that state when it is done, so you do not have to save the graphics state yourself. So I don't really know where to put that `CGContextSetShadowWithColor()` or anything else if I can use it. Regards

Original source