Objective-c View添加虚线
2016-04-26 00:00
260 查看
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 , @8];
//实线边框
// borderLayer.lineDashPattern = nil;
borderLayer.fillColor = [UIColor clearColor].CGColor;
borderLayer.strokeColor = [UIColor redColor].CGColor;
[view.layer addSublayer:borderLayer];
[self.view addSubview:view];
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 , @8];
//实线边框
// borderLayer.lineDashPattern = nil;
borderLayer.fillColor = [UIColor clearColor].CGColor;
borderLayer.strokeColor = [UIColor redColor].CGColor;
[view.layer addSublayer:borderLayer];
[self.view addSubview:view];
相关文章推荐
- Objective-c nil & 初始化
- NtQueryObject 函数
- Foundation => Objective-C _ Part2
- Objective-C语法之KVC使用
- iOS开发系列—Objective-C之内存管理
- RCNN学习笔记(6):You Only Look Once(YOLO):Unified, Real-Time Object Detection
- runtime学习之 - 黑魔法 Swizzling,改变系统方法!
- Objective-c之strong和weak
- NSObject 的 load 和 initialize 方法
- 对象&类&元类(Object & Class & Meta Class)
- Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V解决办法
- Objective-C GCC Code Block Evaluation C Extension ({…})语法
- Object.defineProperty 函数 (JavaScript)
- Objective-C字面量语法总结
- protocol的介绍与简单实用
- Cloneable接口和Object的clone()方法
- 缺少动态链接库: libthrift-0.9.3.so: cannot open shared object file: No such file or directory
- Objective-C Blocks 小测验
- Json工具类,实现了反射将整个Object转换为Json对象的功能,支持Hibernate的延迟加
- 将JsonObject转换成HashMap