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];
[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开发画虚线的方法
- IOS绘制虚线的方法总结
- iOS 画虚线的两种方法
- iOS绘制虚线方法
- IOS绘制虚线的方法,可以给cell设置虚线分割线
- iOS绘制虚线方法
- ios画虚线的方法
- iOS中画虚线的方法【项目中可能会用到】
- iOS 画虚线方法总结
- iOS画虚线方法
- iOS 绘制虚线的三种方法
- [iOS 绘制虚线] 转: iOS 绘制虚线的三种方法
- iOS简单实现虚线的小方法
- iOS绘制虚线方法【原创】
- iOS开发画虚线的方法
- iOS 绘制虚线的三种方法
- Catalyst6509从CatOS到IOS升级方法
- firefox的超链接点击去除扩大的难看虚线的解决方法
- Cisco专题:路由器IOS升级方法总结
- FireFox下出现虚线轮廓解决的方法