Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically setup the layer of an NSView

Tags:

cocoa

calayer

What is the right way to do this? Here is what I am trying. But display is never called on dotLayer:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    DotLayer *dotLayer = [[DotLayer alloc]init ];
    dotLayer.frame= CGRectMake(10, 10, 100, 100);
    dotLayer.nDots = 4;
    NSView *contentView = window.contentView;
    CALayer *layer = [[CALayer alloc]init];
    layer.frame = CGRectMake(0,0,200,200);
    contentView.layer = layer;
    [layer addSublayer:dotLayer];
    [dotLayer setNeedsDisplay];
}

DotLayer is a CALayer subclass.

like image 696
William Jockusch Avatar asked Jan 20 '23 19:01

William Jockusch


1 Answers

Did you forget to setWantsLayer maybe?

contentView.wantsLayer = true

That is often the problem!

like image 137
Fattie Avatar answered Jan 23 '23 09:01

Fattie