2012-07-30 78 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