欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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];
}




相关标签: 虚线

上一篇:

下一篇: