Is it possible to draw just a curve with a given line width using CAShapeLayer? It seems it can only draw filled shapes. I want to draw an animated plot graph. Just a line, not a shape.
Asked
Active
Viewed 1,426 times
1 Answers
5
Well it seems you can in fact draw lines with CAShapeLayers. Try something like this:
UIBezierPath *graphPath = [UIBezierPath bezierPath];
[graphPath moveToPoint:CGPointMake(x, y)];
[graphPath addLineToPoint:CGPointMake(x, y + h)];
[graphPath closePath];
Then put it in a CAShapeLayer:
CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
[shapeLayer setFrame: aFrame];
[shapeLayer setPath: [graphPath CGPath]];
[shapeLayer setStrokeColor:[[UIColor blackColor] CGColor]];
[shapeLayer setMasksToBounds:YES];
You can change graphPath
to plot any curve/line you want to graph.
Hope this helps!

pasawaya
- 11,515
- 7
- 53
- 92
-
2Thanks a lot. Upvoted! To get only the line, I had to set fillColor to nil. – Proud Member Jul 30 '12 at 11:18