iOS 让view圆角虚线边框

来源:互联网 发布:智慧科技与云计算 编辑:程序博客网 时间:2024/04/29 00:39
UIBezierPath *maskPath=[[UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(10, 10)] bezierPathByReversingPath];
CAShapeLayer *border = [CAShapeLayer layer];
// 线条颜色
border.strokeColor = [UIColor hexStringToColor:@"#999999"].CGColor;
border.masksToBounds = YES;

border.fillColor = nil;
border.path = maskPath.CGPath;
border.frame = view.bounds;

border.lineWidth = 1;
border.lineCap = @"square";
// 第一个是 线条长度 第二个是间距 nil时为实线
border.lineDashPattern = @[@6, @4];
[view.layer addSublayer:border];