iOS画虚线------
来源:互联网 发布:修改oracle数据库时间 编辑:程序博客网 时间:2024/06/05 12:01
直接上代码了
// 画虚线 // 创建一个imageView 高度是你想要的虚线的高度 一般设为2 UIImageView *lineImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, kScreenWidth, 1)]; // 调用方法 返回的iamge就是虚线 [self drawDashLine:lineImg lineLength:4 lineSpacing:3 lineColor:GCOLOR];// lineImg.backgroundColor = GCOLOR; // 添加到控制器的view上 [self addSubview:lineImg]; self.lineImg = lineImg; [lineImg mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(@0); make.top.equalTo(staImg.mas_bottom).offset(5); make.height.mas_equalTo(@1); }];/** ** lineView: 需要绘制成虚线的view ** lineLength: 虚线的宽度 ** lineSpacing: 虚线的间距 ** 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]; // 设置虚线颜色为 [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];}
阅读全文
0 0
- iOS 画虚线
- iOS 画虚线 cgcontext
- iOS画虚线
- iOS 画虚线
- iOS 画虚线
- iOS:绘图画虚线
- ios 画虚线
- ios 画虚线
- iOS 画虚线
- iOS画虚线
- iOS画虚线
- iOS画虚线边框
- ios: 画虚线
- iOS开发 画虚线
- iOS画虚线
- iOS画虚线方法
- ios 画虚线方法
- IOS画虚线
- 移植QT5.6到嵌入式开发板(史上最详细的QT移植教程)
- 上传文件功能笔记
- 为什么Button,ImageButton有焦点,textview,imageview没有焦点
- 网络攻击技术开篇——SQL Injection
- xcode各班本下载地址
- iOS画虚线------
- Linux学习:Linux内核编译
- ubuntu nsq安装与配置
- USB WIFI移植
- UGUI点击按钮穿透、UI跟随摄像机旋转
- Quartz 定时任务框 简单使用
- django的视图和URL配置
- java 集合 List Map Set
- Netty系列之Netty线程模型