
When using bezier drawing, the graph can exceed the frame of the BEMSimpleLineGraphView. That is fine, however it looks weird with a gradient background.
I have looked into the code, however I was unable to produce a fix:
CGContextRef ctx = UIGraphicsGetCurrentContext();
if (self.topGradient != nil) {
CGContextSaveGState(ctx);
CGContextAddPath(ctx, [fillTop CGPath]);
CGContextClip(ctx);
CGContextDrawLinearGradient(ctx, self.topGradient, CGPointZero, CGPointMake(0, CGRectGetMaxY(fillTop.bounds)), 0);
CGContextRestoreGState(ctx);
}
if (self.bottomGradient != nil) {
CGContextSaveGState(ctx);
CGContextAddPath(ctx, [fillBottom CGPath]);
CGContextClip(ctx);
CGContextDrawLinearGradient(ctx, self.bottomGradient, CGPointZero, CGPointMake(0, CGRectGetMaxY(fillBottom.bounds)), 0);
CGContextRestoreGState(ctx);
}
This is the drawing code, called in UIView drawRect. In that method the clipping path is already set to view.frame, so that's not the right place to draw the gradient. The CAShapeLayer otoh have no problems drawing outside their frame (just try setting fill color on a shapelayer that has the fillBottom path).
I tried subclassing a CAShapeLayer to draw a custom gradient background as that looked promising, but I couldn't get it working (wouldn't call the draw method).
I guess this is a change that would be quick to do for someone that actually understands CALayers (i.e. not me :-( ). Anyone able to help here?