由于项目需要,最近接触了一些绘图的知识,现在记录下来学习过程。
首先看一下效果图:
首先来看左边柱状图的实现:
1.创建和使用一个path对象的过程是分开的。创建path步骤:
(1)创建一个Bezier path对象。
(2)使用方法moveToPoint:去设置初始线段的起点。
(3)添加line或者curve去定义一个或者多个subpaths。
(4)改变UIBezierPath对象跟绘图相关的属性。
UIBezierPath *progressline = [UIBezierPath bezierPath];
[progressline moveToPoint:CGPointMake(self.frame.size.width/2.0, self.frame.size.height+self.frame.size.width/2.0)];
[progressline addLineToPoint:CGPointMake(self.frame.size.width/2.0, (1 - percent) * self.frame.size.height+self.frame.size.width/2.0)];
[progressline setLineCapStyle:kCGLineCapSquare];
_barLayer.path = progressline.CGPath;
2.CAShapeLayer的strokeStart和strokeEnd属性
1 keyPath = strokeStart 动画的fromValue = 0,toValue = 1