I've got a custom layer which is sub-layer of something else. The problem is, my layer can't know it's size until I'm in drawLayer:inContext:
.
When I don't change the bounds/frame of my layer everything draws perfectly.
When I add in the the line to change frame/bounds, my background looks perfect, but my content doesn't exist. It looks like the content is clipping off the original bounds instead of the new (bigger) bounds so I see nothing but the background.
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context {
CGFloat initialGraphContentsWidth = graph.frame.size.width - graph.leftMargin;
CGFloat initialGraphContentsHeight = graph.frame.size.height - graph.bottomMargin - graphHelper.topMargin;
self.frame = CGRectMake(0, 0, initialGraphContentsWidth, initialGraphContentsHeight);
self.position = CGPointMake(graphHelper.leftMargin + 1, graphHelper.topMargin + 1);
self.backgroundColor = [UIColor greenColor].CGColor;
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextAddRect(context, CGRectMake(0, 0, 20, 20));
}
So how to I dynamically change my bounds and still get my content to appear?
I tried setting up a CATransaction
with a duration of 0, but that did nothing.