iOS之虚线边框

我这里是给一个按钮加一个虚线边框

     

    self.btnlayer = [UIButton buttonWithType:UIButtonTypeCustom];

    self.btnlayer.frame = CGRectMake(20, 20, ScreenWidth-40, 80);

    self.btnlayer.backgroundColor = [UIColor whiteColor];

    self.btnlayer.hidden = YES;

    

    //下面就是给button 的 layer层加上边框

    CAShapeLayer *border = [CAShapeLayer layer];

    border.strokeColor = [UIColor lightGrayColor].CGColor;

    border.fillColor = nil;

    border.path = [UIBezierPath bezierPathWithRect:self.btnlayer.bounds].CGPath;

    border.frame = self.btnlayer.bounds;

    border.lineWidth = 1.f;

    border.lineCap = @"square";

    border.lineDashPattern = @[@4, @2];


    [self.btnlayer.layer addSublayer:border];


你可能感兴趣的:(iOS)