画虚线

//画虚线

    CAShapeLayer *shapeLayer = [CAShapeLayer layer];

    [shapeLayer setBounds:self.backView.bounds];

    [shapeLayer setPosition:self.backView.center];

    [shapeLayer setFillColor:[[UIColor clearColor] CGColor]];

    

    // 设置虚线颜色为blackColor

    [shapeLayer setStrokeColor:[[UIColor blackColor] CGColor]];

    [shapeLayer setStrokeColor:[[UIColor colorWithRed:223/255.0 green:223/255.0 blue:223/255.0 alpha:1.0f] CGColor]];

    

    // 3.0f设置虚线的宽度

    [shapeLayer setLineWidth:0.5f];

    [shapeLayer setLineJoin:kCALineJoinRound];

    

    // 3=线的宽度 1=每条线的间距

    [shapeLayer setLineDashPattern:

     [NSArray arrayWithObjects:[NSNumber numberWithInt:4],

      [NSNumber numberWithInt:2],nil]];

    

    //设置path

    CGMutablePathRef path = CGPathCreateMutable();

    CGPathMoveToPoint(path, NULL, self.coupNumberLabel.frame.origin.x + self.coupNumberLabel.frame.size.width, 10);//x  虚线的x轴起点  y  虚线的y轴起点

    CGPathAddLineToPoint(path, NULL,self.coupNumberLabel.frame.origin.x + self.coupNumberLabel.frame.size.width,164/2 - 10);   //x  虚线的X轴起点   y  虚线的高度

    [shapeLayer setPath:path];

    CGPathRelease(path);

    

    [[self layer] addSublayer:shapeLayer];

posted @ 2016-05-12 11:17  xiaolingling  阅读(267)  评论(0编辑  收藏  举报