ios 画虚线方法

来源:互联网 发布:java线程池是否繁忙 编辑:程序博客网 时间:2024/04/27 23:19

    CAShapeLayer *shapeLayer = [CAShapeLayer layer];    [shapeLayer setBounds:self.lineLayer.bounds];    [shapeLayer setPosition:CGPointMake(CGRectGetWidth(self.lineLayer.frame), CGRectGetHeight(self.lineLayer.frame)/2)];    [shapeLayer setFillColor:[UIColor clearColor].CGColor];    //  设置虚线颜色为blackColor    [shapeLayer setStrokeColor:[UIColor blackColor].CGColor];    //  设置虚线宽度    [shapeLayer setLineWidth:CGRectGetWidth(self.lineLayer.frame)];    [shapeLayer setLineJoin:kCALineJoinRound];    [shapeLayer setLineCap:kCALineCapRound];    //  设置线宽,线间距    [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:1], [NSNumber numberWithInt:3], nil]];    //  设置路径    CGMutablePathRef path = CGPathCreateMutable();    CGPathMoveToPoint(path, NULL, 0, 0);    CGPathAddLineToPoint(path, NULL,0, (MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height))/2);    [shapeLayer setPath:path];    CGPathRelease(path);    //  把绘制好的虚线添加上来    [self.lineLayer.layer addSublayer:shapeLayer];


0 0