Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Varying lineWidth in a CAShapeLayer

I'm working on a little project where I want to draw a bezier curve. I want to be able to vary the lineWidth in different portions of the drawing.

Here's what I have:

CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.frame = self.animationLayer.bounds;
pathLayer.bounds = pathRect;
pathLayer.geometryFlipped = YES;
pathLayer.path = path.CGPath;
pathLayer.strokeColor = [[UIColor blackColor] CGColor];
pathLayer.fillColor = nil;
pathLayer.lineWidth = 1.0f;
pathLayer.lineJoin = kCALineJoinBevel;

How would I vary the width of the line? One solution might be to have multiple UIBezierPaths with multiple CAShapeLayers, but it seems there should be a simpler, more elegant solution (something along the lines of specifying the lineWidth at the level where the UIBezierPath lines are specified).

Thanks!

like image 603
donkim Avatar asked Oct 21 '11 00:10

donkim


1 Answers

UIBezierPath only has one lineWidth property, so it's not possible to draw varying line widths with one path. You would have to use multiple paths to achieve this effect.

like image 54
omz Avatar answered Oct 25 '22 06:10

omz