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

2017-03-21  本文已影响0人  蛋哥是只猫
- (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;
}

效果图:

图片.png
上一篇 下一篇

猜你喜欢

热点阅读