NSView 设置背景色

2017-01-14  本文已影响133人  墨凌风起

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];
上一篇 下一篇

猜你喜欢

热点阅读