Draw dotted (not dashed!) line, with IBDesignable in 2017

前端 未结 10 1718
死守一世寂寞
死守一世寂寞 2020-11-28 03:25

It\'s easy to draw a dashed line with UIKit. So:

CGFloat dashes[] = {4, 2};
[path setLineDash:dashes count:2 phase:0];
[path stroke];
         


        
10条回答
  •  旧时难觅i
    2020-11-28 04:12

    I have implemented following piece of code to add border with dotted style at bottom of titleLabel (UILabel) in viewDidAppear:

    CAShapeLayer *shapelayer = [CAShapeLayer layer];
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(0.0, titileLabel.frame.size.height-2)];
    [path addLineToPoint:CGPointMake(SCREEN_WIDTH, titileLabel.frame.size.height-2)];
    UIColor *fill = [UIColor colorWithRed:0.80f green:0.80f blue:0.80f alpha:1.00f];
    shapelayer.strokeStart = 0.0;
    shapelayer.strokeColor = fill.CGColor;
    shapelayer.lineWidth = 2.0;
    shapelayer.lineJoin = kCALineJoinRound;
    shapelayer.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:2],[NSNumber numberWithInt:3 ], nil];
    shapelayer.path = path.CGPath;
    
    [titileLabel.layer addSublayer:shapelayer];
    

    Refrence : https://gist.github.com/kaiix/4070967

提交回复
热议问题