iOS绘制虚线方法
2016-11-17 17:16
127 查看
/** ** lineView: 需要绘制成虚线的view ** lineLength: 虚线的宽度 //2 ** lineSpacing: 虚线的间距//1 ** lineColor: 虚线的颜色 **/ + (void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor { CAShapeLayer *shapeLayer = [CAShapeLayer layer]; [shapeLayer setBounds:lineView.bounds]; [shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame))]; [shapeLayer setFillColor:[UIColor clearColor].CGColor]; // 设置虚线颜色为blackColor [shapeLayer setStrokeColor:lineColor.CGColor]; // 设置虚线宽度 [shapeLayer setLineWidth:CGRectGetHeight(lineView.frame)]; [shapeLayer setLineJoin:kCALineJoinRound]; // 设置线宽,线间距 [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]]; // 设置路径 CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, 0, 0); CGPathAddLineToPoint(path, NULL, CGRectGetWidth(lineView.frame), 0); [shapeLayer setPath:path]; CGPathRelease(path); // 把绘制好的虚线添加上来 [lineView.layer addSublayer:shapeLayer]; }
效果如下:
相关文章推荐
- IOS绘制虚线的方法总结
- iOS 绘制虚线的三种方法
- [iOS 绘制虚线] 转: iOS 绘制虚线的三种方法
- iOS 绘制虚线的三种方法
- iOS绘制虚线方法【原创】
- IOS绘制虚线的方法,可以给cell设置虚线分割线
- iOS绘制虚线方法
- 32.CGBitmapContextCreate 在配备Retina的设备上绘制模糊的 解决方法 iOS截屏模糊
- iOS 画虚线的两种方法
- iOS 画虚线方法总结
- ios 绘制虚线 CGContextSetLineDash函数的参数
- iOS学习笔记-058.绘制的多种方法——矩形
- iOS开发中使用Quartz2D绘制上下文栈和矩阵的方法
- 一个绘制虚线的非常规函数(常规方法,打印机上绘制不出虚线)
- mac 下绘制虚线的方法
- ios绘制方法
- iOS 开发之绘制虚线
- ios 画虚线方法
- 比较少见的绘制虚线的方法
- [ActionScript 3.0] AS3虚线绘制方法