构造各种各样的图形? UIBezierPath(用来指定绘制图形路径)和CAShapeLayer(根据路径绘制图形)
UIBezierPath
- 添加直线
- (void)addLineToPoint:(CGPoint)point;
- 添加二次贝赛尔曲线
- (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint;
- 三次贝赛尔曲线
- (void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1
controlPoint2:(CGPoint)controlPoint2;
两个喵点
绘制三个边的矩形
//矩形框.
CGFloat beginX = 60;
CGFloat beginY = 200;
CGFloat lineWidth = 3;
CGFloat horizontalLineWidth = 230;
CGFloat endX = beginX+horizontalLineWidth+lineWidth;
CGFloat verticalLineHeight = 100;
CGFloat endY = beginY+verticalLineHeight+2*lineWidth;
_trackLayer = [CAShapeLayer layer];
[self.contentImgView.layer addSublayer:_trackLayer];
_trackLayer.fillColor = [UIColor clearColor].CGColor;
_trackLayer.strokeColor = [UIColor redColor].CGColor;
_trackLayer.opacity = 1.0f;
_trackLayer.lineCap = kCALineCapRound;//路径的终点形状.
_trackLayer.lineJoin = kCALineJoinRound;//路径的连接点形状
_trackLayer.lineWidth = lineWidth;
//这里仅仅设置好路径即可. 其他的属性如lineWidth、lineCapStyle等可通过CAShapeLayer设置
_bezierPath = [UIBezierPath bezierPath];
/*
_bezierPath.lineWidth = lineWidth;
_bezierPath.lineCapStyle = kCGLineCapRound;
_bezierPath.lineJoinStyle = kCGLineJoinRound;
通过CAShapeLayer设置
*/
[_bezierPath moveToPoint:CGPointMake(beginX, beginY)];
[_bezierPath addLineToPoint:CGPointMake(beginX+horizontalLineWidth, beginY)];
[_bezierPath addQuadCurveToPoint:CGPointMake(endX, beginY+lineWidth) controlPoint:CGPointMake(endX, beginY)];
[_bezierPath addLineToPoint:CGPointMake(endX, endY-lineWidth)];
[_bezierPath addQuadCurveToPoint:CGPointMake(endX-lineWidth, endY) controlPoint:CGPointMake(endX, endY)];
[_bezierPath addLineToPoint:CGPointMake(beginX, endY)];
_trackLayer.path = _bezierPath.CGPath;