I have my own minimal view class with this:
- (void) awakeFromNib
{
NSLog(@"awakeFromNib!");
[self.layer setDelegate:self];
[self.layer setFrame:CGRectMake(30, 30, 250, 250)];
self.layer.masksToBounds = YES;
self.layer.cornerRadius = 5.0;
self.layer.backgroundColor = [[UIColor redColor] CGColor];
[self setNeedsDisplay];
}
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
NSLog(@"drawing!");
}
drawLayer: inContext is never called, although I see the layer as a red rectangular rectangle. What am I missing?
EDIT: from Apple docs
You can draw content for your layer, or better encapsulate the layer settings by creating a delegate class that implements one of the following methods: displayLayer: or drawLayer: inContext :.
An implementation of the delegate method for drawing content will not automatically force the layer to draw using the implementation. Instead, you must explicitly tell the layer instance to cache the contents again, either by sending it the setNeedsDisplay or setNeedsDisplayInRect: message or setting its needsDisplayOnBoundsChange property YES.
Besides
drawLayer: InContext:
, drawInContext:.