-(void)boundingRectangleForView:(UIView *)fatherView{
CGRect frame = fatherView.bounds;
CGFloat cornerRadius = 10.0f;
CAShapeLayer *borderLayer = [CAShapeLayer layer];
CGMutablePathRef path = CGPathCreateMutable();
//drawing a border around a view
CGPathMoveToPoint(path, NULL, 0, frame.size.height - cornerRadius);
CGPathAddLineToPoint(path, NULL, 0, cornerRadius);
CGPathAddArc(path, NULL, cornerRadius, cornerRadius, cornerRadius, M_PI, -M_PI_2, NO);
CGPathAddLineToPoint(path, NULL, frame.size.width - cornerRadius, 0);
CGPathAddArc(path, NULL, frame.size.width - cornerRadius, cornerRadius, cornerRadius, -M_PI_2, 0, NO);
CGPathAddLineToPoint(path, NULL, frame.size.width, frame.size.height - cornerRadius);
CGPathAddArc(path, NULL, frame.size.width - cornerRadius, frame.size.height - cornerRadius, cornerRadius, 0, M_PI_2, NO);
CGPathAddLineToPoint(path, NULL, cornerRadius, frame.size.height);
CGPathAddArc(path, NULL, cornerRadius, frame.size.height - cornerRadius, cornerRadius, M_PI_2, M_PI, NO);
//path is set as the _shapeLayer object's path
borderLayer.path = path;
CGPathRelease(path);
borderLayer.backgroundColor = [[UIColor clearColor] CGColor];
borderLayer.frame = frame;
borderLayer.masksToBounds = NO;
[borderLayer setValue:[NSNumber numberWithBool:NO] forKey:@"isCircle"];
borderLayer.fillColor = [[UIColor clearColor] CGColor];
borderLayer.strokeColor = [[UIColor redColor] CGColor];
borderLayer.lineWidth = 1;
borderLayer.lineDashPattern =@[@4, @4];;
borderLayer.lineCap = kCALineCapRound;
[fatherView.layer addSublayer:borderLayer];
fatherView.layer.cornerRadius = 10;
}
网友评论