博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Objective-c View添加虚线
阅读量:6892 次
发布时间:2019-06-27

本文共 1173 字,大约阅读时间需要 3 分钟。

hot3.png

 CGSize screenSize = [UIScreen mainScreen].bounds.size;

    CGFloat viewWidth = 200;

    CGFloat viewHeight = 200;

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake((screenSize.width - viewWidth)/2, (screenSize.height - viewHeight) / 2, viewWidth, viewHeight)];

    view.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];

    view.layer.cornerRadius = CGRectGetWidth(view.bounds)/2;

    CAShapeLayer *borderLayer = [CAShapeLayer layer];

    borderLayer.bounds = CGRectMake(0, 0, viewWidth, viewHeight);

    borderLayer.position = CGPointMake(CGRectGetMidX(view.bounds), CGRectGetMidY(view.bounds));

    

    //    borderLayer.path = [UIBezierPath bezierPathWithRect:borderLayer.bounds].CGPath;

    borderLayer.path = [UIBezierPath bezierPathWithRoundedRect:borderLayer.bounds cornerRadius:CGRectGetWidth(borderLayer.bounds)/2].CGPath;

    borderLayer.lineWidth = 1. / [[UIScreen mainScreen] scale];

    //虚线边框

    borderLayer.lineDashPattern = , @8];

    //实线边框

    //    borderLayer.lineDashPattern = nil;

    borderLayer.fillColor = [UIColor clearColor].CGColor;

    borderLayer.strokeColor = [UIColor redColor].CGColor;

    [view.layer addSublayer:borderLayer];

    

    [self.view addSubview:view];

转载于:https://my.oschina.net/u/2483781/blog/666319

你可能感兴趣的文章
shell历史命令记录功能
查看>>
kali linux软件源
查看>>
centos6设置静态IP
查看>>
cocos2d_x在windows环境下的方向键支持
查看>>
Mysql数据库恢复,Ibdata1文件删除数据恢复成功
查看>>
Maven学习总结(11)——Maven Tomcat7自动部署
查看>>
Shell 中常用的sqlplus 代码段
查看>>
Maven学习总结(1)——Maven入门
查看>>
Linux java环境配置
查看>>
mysql ====查询命令介绍(5)
查看>>
Ffmpeg,mencoder视频格式转换
查看>>
【经验收集】完全卸载SQLServer 2008 R2的步骤
查看>>
Spring Boot 项目启动顺序以及常见注解作用
查看>>
java基础(2)
查看>>
zabbix安装界面报连接不到数据
查看>>
一首Python的打油诗
查看>>
pjsip 同时使用多套音频设备
查看>>
DevOps:怎么实现源代码注释和系统文档的自动化更新?
查看>>
make 中的路径搜索(十二)
查看>>
zabbix agent 端主动注册
查看>>