CAShapeLayer
CAShapeLayer的几个重点:
1:它本身没有形状,它的形状依附于你给的path,所以你必须要给一个path给它,即使path不完整也能自动首尾连接;
2. strokeStart以及strokeEnd代表着在这个path中所占用的百分比;
3. CAShapeLayer动画仅仅限于沿着边缘的动画效果,它实现不了填充效果;
创建一个CAShapeLayer:
1:创建一个背景view:
UIView*bgv=[[UIView alloc]initWithFrame:self.view.bounds];
bgv.backgroundColor=[UIColor lightGrayColor];
[self.view addSubview:bgv];
2:贝塞尔曲线(创建指定圆角的矩形)
CGRect rectR=CGRectMake(50, 50, 200, 100);
UIRectCorner corners=UIRectCornerBottomLeft|UIRectCornerBottomRight|UIRectCornerTopLeft;//指定角
UIBezierPath*path=[UIBezierPath bezierPathWithRoundedRect:rectR byRoundingCorners:corners cornerRadii:CGSizeMake(20, 20)];
3: 创建一个shapeLayer
CAShapeLayer*shapeLayer=[CAShapeLayer layer];
shapeLayer.strokeColor=[UIColor redColor].CGColor;//边缘线的颜色
shapeLayer.fillColor=[UIColor clearColor].CGColor;//闭封区域填充的颜色
shapeLayer.lineWidth=5;// 线宽
shapeLayer.path=path.CGPath;//给定的绘制path
shapeLayer.lineJoin=kCALineJoinRound;//节点处的形状
shapeLayer.lineCap=kCALineCapRound;//线的形状
[bgv.layer addSublayer:shapeLayer];//添加到layer(层)