美文网首页
NSView 设置背景色

NSView 设置背景色

作者: 墨凌风起 | 来源:发表于2017-01-14 09:13 被阅读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];

相关文章

网友评论

      本文标题:NSView 设置背景色

      本文链接:https://www.haomeiwen.com/subject/ofrebttx.html