2012-07-30 74 views

回答

5

好吧,看来你实际上可以用CAShapeLayers画线。尝试是这样的:

UIBezierPath *graphPath = [UIBezierPath bezierPath]; 
[graphPath moveToPoint:CGPointMake(x, y)]; 
[graphPath addLineToPoint:CGPointMake(x, y + h)]; 
[graphPath closePath]; 

然后把它放在一个CAShapeLayer:

CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init]; 
[shapeLayer setFrame: aFrame]; 
[shapeLayer setPath: [graphPath CGPath]]; 
[shapeLayer setStrokeColor:[[UIColor blackColor] CGColor]]; 
[shapeLayer setMasksToBounds:YES]; 

您可以更改graphPath绘制你想图中的任何曲线/线。

希望这会有所帮助!

+0

@ProudMember - 我编辑了我的答案。 – pasawaya 2012-07-30 10:36:16

+1

非常感谢。 Upvoted!为了仅获得该行,我必须将fillColor设置为零。 – 2012-07-30 11:18:25