如何使用bezierpath创建具有多行和不同颜色的折线图

时间:2016-03-01 13:35:58

标签: ios

我创建了一个bezierpath并将其添加到cashapelayer但我无法改变路径的颜色

//创建路径

UIBezierPath *graphPath = [[UIBezierPath alloc]init];
[graphPath setLineWidth:30];
[[UIColor blackColor] setStroke];
[graphPath moveToPoint:CGPointMake(30 , 30)];
[graphPath addLineToPoint:CGPointMake(30,600)];
[graphPath addLineToPoint:CGPointMake(380, 600)];

//添加图层

的路径
CAShapeLayer *graphLayout = [CAShapeLayer layer];
graphLayout.frame = CGRectMake(0, 65, VIEW_WIDTH, VIEW_HEIGHT);
graphLayout.fillColor = [[UIColor clearColor] CGColor];
graphLayout.strokeColor = [UIColor redColor].CGColor;
graphLayout.lineWidth = 2;
graphLayout.path = [graphPath CGPath];

[self.layer addSublayer:graphLayout];
//animation
 drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
drawAnimation.duration = 3;
drawAnimation.repeatCount = 1.0;

drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
drawAnimation.toValue   = [NSNumber numberWithFloat:1.0f];

[graphLayout addAnimation:drawAnimation forKey:@"drawCircleAnimation"];

0 个答案:

没有答案
相关问题