2
是否可以使用CAShapeLayer繪製給定線寬的曲線?看起來它只能畫出填充的形狀。我想畫一個動畫劇情圖。只是一條線,而不是一個形狀。如何用CAShapeLayer繪製圖表?
是否可以使用CAShapeLayer繪製給定線寬的曲線?看起來它只能畫出填充的形狀。我想畫一個動畫劇情圖。只是一條線,而不是一個形狀。如何用CAShapeLayer繪製圖表?
好吧,看來你實際上可以用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
繪製你想圖中的任何曲線/線。
希望這會有所幫助!
@ProudMember - 我編輯了我的答案。 – pasawaya 2012-07-30 10:36:16
非常感謝。 Upvoted!爲了僅獲得該行,我必須將fillColor設置爲零。 – 2012-07-30 11:18:25