NSView 设置背景色

iOS中UIView设置背景色是

UIView *view= [[UIView alloc]init];
view.backgroundColor = [UIcolor redcolor];

OS X中NSView没有backgroundColor这个属性,所以无法直接设置

 CALayer *viewLayer = [CALayer layer];
 NSView *backgroundView= [[NSView alloc]init];
 [backgroundView setWantsLayer:YES];
 [backgroundView setLayer:viewLayer];
 backgroundView.layer.backgroundColor = [NSColor colorWithRed:0.14 green:0.62 blue:0.93 alpha:1.0].CGColor;
 [backgroundView setNeedsDisplay:YES];

你可能感兴趣的:(NSView 设置背景色)