- (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
网友评论