Dashed line border around UIView

后端 未结 23 2340
粉色の甜心
粉色の甜心 2020-12-02 04:16

How do I add dashed line border around UIView.

Something Like this

\"\"

23条回答
  •  抹茶落季
    2020-12-02 04:23

    If you want this to work with cornerRadius then try this

    tagView.clipsToBounds = YES;
    tagView.layer.cornerRadius = 20.0f;
    tagView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    CAShapeLayer *yourViewBorder = [CAShapeLayer layer];
    yourViewBorder.strokeColor = [UIColor blackColor].CGColor;
    yourViewBorder.fillColor = nil;
    yourViewBorder.lineDashPattern = @[@2, @2];
    yourViewBorder.frame = tagView.bounds;
    
    // Create the path for to make circle
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:tagView.bounds
                                                   byRoundingCorners:UIRectCornerAllCorners
                                                         cornerRadii:CGSizeMake(20, 20)];
    
    
    yourViewBorder.path = maskPath.CGPath;
    
    [tagView.layer addSublayer:yourViewBorder];
    

提交回复
热议问题