【问题标题】:Setting Colour to an NSView [duplicate]将颜色设置为 NSView [重复]
【发布时间】:2013-04-22 05:06:01
【问题描述】:

我正在开发一个菜单栏应用程序,它有一个继承自 NSView 的自定义 BackGroundView,它在 PanelController 类中声明为名为“backgroundView”的属性。我需要为此背景视图设置紫罗兰色。谁能告诉我如何做到这一点。在此先感谢...

【问题讨论】:

标签: objective-c cocoa nsview


【解决方案1】:

在您的 drawRect: 方法中,您将有类似的内容:

-(void)drawRect:(NSRect)rect
{
    [[NSColor colorWithCalibratedRed:1 green:0 blue:1 alpha:1] set]; //Not sure if this is violet, just change the color yourself

    [NSBezierPath fillRect:rect];
}

【讨论】:

  • 但是,当我使用它时,颜色甚至会填满菜单栏和视图之间的空间。我只希望背景视图有颜色。
猜你喜欢
  • 1970-01-01
  • 2011-11-24
  • 2021-05-24
  • 2020-10-12
  • 2013-08-12
  • 2018-05-15
  • 2021-05-12
  • 2023-03-12
  • 2014-07-29
相关资源
最近更新 更多