使用多种颜色iOS绘制一条线

时间:2015-11-20 22:04:32

标签: ios objective-c uibezierpath cashapelayer

我正画一条颜色为黑色的线。但我想在这一行中不止一种颜色。例如; 40%黄色,30%黑色,30%蓝色。有没有办法做到这一点?

感谢您的回答和兴趣。

这是我的代码;

- (void)drawRect:(CGRect)rect {
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, self.frame.size.height/2)];
[path addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height/2)];

CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.frame = self.bounds;
pathLayer.path = path.CGPath;
pathLayer.lineCap = kCALineCapRound;
//pathLayer.lineCap = kCALineCapSquare;

pathLayer.strokeColor = [[UIColor blackColor] CGColor];
pathLayer.fillColor = nil;
pathLayer.lineWidth = 15.0f;
pathLayer.cornerRadius = 2.0f;
pathLayer.lineJoin = kCALineJoinBevel;
//pathLayer.lineDashPattern = @[@15];

[self.layer addSublayer:pathLayer];

}

0 个答案:

没有答案