Created
January 7, 2020 11:52
-
-
Save qy1010/28747a520dad64baaf4cff5344539e41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)addLineDashPattern:(UIView *)view | |
{ | |
[view.layer.sublayers enumerateObjectsUsingBlock:^(__kindof CALayer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { | |
[obj removeFromSuperlayer]; | |
obj = nil; | |
}]; | |
view.layer.masksToBounds = YES; | |
view.layer.cornerRadius = view.frame.size.width / 2; | |
CAShapeLayer *border = [CAShapeLayer layer]; | |
//虚线的颜色 | |
border.strokeColor = [UIColor colorNamed:@"locationViewBackgroundColor"].CGColor; | |
//填充的颜色 | |
border.fillColor = [UIColor clearColor].CGColor; | |
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:view.bounds cornerRadius:view.size.width / 2]; | |
//设置路径 | |
border.path = path.CGPath; | |
border.frame = view.bounds; | |
//虚线的宽度 | |
border.lineWidth = 3.f; | |
//虚线的间隔 | |
border.lineDashPattern = @[@8, @4]; | |
[view.layer addSublayer:border]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment