码迷,mamicode.com
首页 > 其他好文 > 详细

画虚线

时间:2015-11-04 00:20:25      阅读:154      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!