您的位置:首页 > 移动开发 > IOS开发

ios 画虚线方法

2016-12-29 09:05 183 查看
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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios