首页 > 其他 > 详细

画虚线

时间:2015-11-04 00:18:29      阅读:317      评论:0      收藏:0      [点我收藏+]
 1 + (void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor
 2 {
 3     CAShapeLayer *shapeLayer = [CAShapeLayer layer];
 4     [shapeLayer setBounds:lineView.bounds];
 5     [shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame))];
 6     [shapeLayer setFillColor:[UIColor clearColor].CGColor];
 7     //  设置虚线颜色
 8     [shapeLayer setStrokeColor:lineColor.CGColor];    
 9     //  设置虚线宽度
10     [shapeLayer setLineWidth:CGRectGetHeight(lineView.frame)];
11     [shapeLayer setLineJoin:kCALineJoinRound];   
12     //  设置线宽,线间距
13     [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];
14     //  设置路径
15     CGMutablePathRef path = CGPathCreateMutable();
16     CGPathMoveToPoint(path, NULL, 0, 0);
17     CGPathAddLineToPoint(path, NULL, CGRectGetWidth(lineView.frame), 0);   
18     [shapeLayer setPath:path];
19     CGPathRelease(path);  
20     //  把绘制好的虚线添加上来
21     [lineView.layer addSublayer:shapeLayer];
22 }

 

画虚线

原文:http://www.cnblogs.com/cityingma/p/4934674.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!