iOS开发中为视图添加指定个数边框

- (UIView *)borderForView:(UIView *)originalView color:(UIColor *)color{
    UIBezierPath * bezierPath = [UIBezierPath bezierPath];
   
    [bezierPath moveToPoint:CGPointMake(0,originalView.frame.size.height)];

    [bezierPath addLineToPoint:CGPointMake(0, 0)];
    
    [bezierPath addLineToPoint:CGPointMake(originalView.frame.size.width, 0)];
    
    [bezierPath addLineToPoint:CGPointMake( originalView.frame.size.width, originalView.frame.size.height)];
    
    CAShapeLayer * shapeLayer = [CAShapeLayer layer];
    
    shapeLayer.strokeColor = color.CGColor;
    
    shapeLayer.fillColor  = [UIColor clearColor].CGColor;
    
    shapeLayer.path = bezierPath.CGPath;
    
    shapeLayer.lineWidth = 1.0f;
    
    [originalView.layer addSublayer:shapeLayer];

    return originalView;
}

效果图:

iOS开发中为视图添加指定个数边框_第1张图片
图片.png

你可能感兴趣的:(iOS开发中为视图添加指定个数边框)