iOS view加虚线边框
程序员文章站
2023-12-24 20:26:45
...
@implementation UIView (dottedLine)
-(void)addBottedlineWidth:(CGFloat)lineWidth lineColor:(UIColor *)lineColor{
CAShapeLayer *border = [CAShapeLayer layer];
border.strokeColor = lineColor.CGColor;
border.fillColor = nil;
border.path = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;
border.frame = self.bounds;
border.lineWidth = lineWidth;
border.lineCap = @"square";
//设置线宽和线间距
border.lineDashPattern = @[@4, @5];
[self.layer addSublayer:border];
}