画线

作者: 番薯大佬 | 来源:发表于2017-11-12 15:56 被阅读5次

    使用CAShapeLayerUIBezierPathUIView上画线。

    //  创建出CAShapeLayer
    CAShapeLayer *linelayer = [CAShapeLayer layer];
    linelayer.frame = CGRectMake(0.0, 0.0, self.scrollView.contentSize.width, self.scrollView.height);;
    linelayer.fillColor = [UIColor clearColor].CGColor;//填充颜色为ClearColor
    // 设置线条的宽度和颜色
    linelayer.lineWidth = 1.0f;
    linelayer.strokeColor = self.xLine.backgroundColor.CGColor;
    
    //
    UIBezierPath *bezierPath = [UIBezierPath bezierPath];
    // 设置线段的起始位置
    [bezierPath moveToPoint:CGPointMake(10.0, 10.0)];
    // 添加点
    [bezierPath addLineToPoint:CGPointMake(0.0, 0.0)];
    [bezierPath addLineToPoint:CGPointMake(100.0, 100.0)];
    [bezierPath addLineToPoint:CGPointMake(130.0, 60.0)];
    [bezierPath addLineToPoint:CGPointMake(180.0, 20.0)];
    
    //
    linelayer.path = bezierPath.CGPath;
    [self.view.layer addSublayer:linelayer];
    
    
    效果.png

    相关文章

      网友评论

          本文标题:画线

          本文链接:https://www.haomeiwen.com/subject/dtxomxtx.html