iOS 画一条虚线
2016-02-17 本文已影响661人
烟影很美
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.position = CGPointMake(1, 2);
shapeLayer.fillColor = nil;
// 设置虚线颜色
shapeLayer.strokeColor = HEXCOLOR(0xcccccc).CGColor;
// 3.0f设置虚线的宽度
shapeLayer.lineWidth = 2.0f;
shapeLayer.lineJoin = kCALineJoinRound;
// 2=线的宽度 3=每条线的间距
shapeLayer.lineDashPattern = @[@2, @3];
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0, 0);
CGPathAddLineToPoint(path, NULL, _allview.width,0);
shapeLayer.path = path;
CGPathRelease(path);
[_allview.layer addSublayer:shapeLayer];