iOS 绘制虚线
来源:互联网 发布:php实现注册登录 编辑:程序博客网 时间:2024/05/01 13:43
效果
绘制虚线的原理是先画一个层,然后给这个层添加一个间断的路径,让这个层按照这个路径显示,具体代码如下:
-(void)AddDottedLine{ //获取屏幕宽高 CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height; CAShapeLayer *shapeLayer = [CAShapeLayer layer]; // 设置虚线颜色为黑色 [shapeLayer setStrokeColor:[UIColor blackColor].CGColor]; //设置虚线的宽度 [shapeLayer setLineWidth:10.0f]; //数组中前一项代表线的宽度,后一项代表每条线的间距 [shapeLayer setLineDashPattern:@[[NSNumber numberWithFloat:30.0f],[NSNumber numberWithFloat:10.0f]]]; //初始化虚线路径path CGMutablePathRef path = CGPathCreateMutable(); //设置起点坐标 CGPathMoveToPoint(path, NULL, x, y); CGPathMoveToPoint(path, NULL, 0, 0); //设置终点坐标 CGPathMoveToPoint(path, NULL, x, y); CGPathAddLineToPoint(path, NULL, screenWidth,screenHeight); //给layer设置路径 [shapeLayer setPath:path]; CGPathRelease(path); //将虚线添加到view的layer上 [self.view.layer addSublayer:shapeLayer];}
0 0
- ios绘制虚线
- iOS 绘制虚线
- IOS绘制虚线
- iOS 绘制虚线
- iOS 开发 绘制虚线
- iOS绘制虚线方法
- IOS 绘制虚线
- iOS绘制虚线方式总结
- iOS绘制虚线方法【原创】
- iOS 开发之绘制虚线
- ios 绘制虚线 CGContextSetLineDash的使用
- [iOS] 绘制虚线CGContextSetLineDash的使用
- iOS 绘制虚线的三种方法
- iOS 绘制虚线的三种方法
- ios 绘制虚线 CGContextSetLineDash的使用
- ios 绘制虚线 CGContextSetLineDash函数的参数
- 绘制虚线
- [iOS 绘制虚线] 转: iOS 绘制虚线的三种方法
- 对char **argv的理解(多级指针)
- MySQL数据库update更新子查询[Err] 1093 - You can't specify target table 'text' for update in FROM clause
- Oracle统计信息
- Mongodb-1
- 不让浏览器缓存js
- iOS 绘制虚线
- HTML DOM Table 对象
- sql中exists,not exists的用法
- GDB调试php扩展错误(Segmentation fault (core dumped))
- Swift快速入门(一)基本类型
- our build settings specify a provisioning profile with the UUID “a1457f8e-1f2f-4f7c-8de1-f3540145b3c
- shell 正则表达式
- Android Studio 那些事| ' ' cannot be applied to '(groovy.lang.Closure)'
- 数据持久化