部分圆角+边框

- (void)setborderCornerRadius:(CGFloat)cornerRadius type:(UIRectCorner)corners lineWidth:(CGFloat)lineWidth  borderColor:(UIColor *)borderColor{
    CGSize radii = CGSizeMake(cornerRadius, cornerRadius);
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:radii];
    CAShapeLayer *maskLayer   = [CAShapeLayer layer];
    maskLayer.frame           = self.bounds;
    maskLayer.path            = path.CGPath;
    self.layer.mask           = maskLayer; //  必须添加 不然会出现边框粗细不对
    
    CAShapeLayer *shapeLayer    = [CAShapeLayer layer];
    shapeLayer.frame            = self.bounds;
    shapeLayer.path             = path.CGPath;
    shapeLayer.lineWidth        = lineWidth;
    shapeLayer.lineCap          = kCALineCapSquare;
    shapeLayer.fillColor        = [UIColor clearColor].CGColor;
    shapeLayer.strokeColor      = borderColor.CGColor;
    [self.layer addSublayer: shapeLayer];
}
layer.mask省略会出现边框粗细不对!

你可能感兴趣的:(部分圆角+边框)