天天看点

给UIView 的子类们 UIButton UILbel等 。。。。加一个虚线圆角的border

给UIView 的子类们 UIButton UILbel等 。。。。加一个虚线圆角的border

xcode 7.0

developTarget 9.0

代码:

- (void)createDotBorderForView:(UIView *)view
{
    view.layer.cornerRadius = f;

    CAShapeLayer *border = [CAShapeLayer layer];
    border.strokeColor = [UIColor orangeColor].CGColor;
    border.cornerRadius = f;
    border.fillColor = nil;
    border.path = [UIBezierPath bezierPathWithRoundedRect:view.bounds cornerRadius:].CGPath;
    border.frame = view.bounds;
    border.lineWidth = f;
    border.lineCap = kCALineCapRound;
    border.lineDashPattern = @[@5, @3];// @5是虚线长度 @3是间距的长度

    [view.layer addSublayer:border];
}
           

传入你想要加虚线的View。

继续阅读