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;
}
效果图:
![](https://img.haomeiwen.com/i4670455/112f765e2807e0d9.png)