0

I have a standard NSPanel set to HUD style. I want to change the background color, primarily because I want to have a toolbar and don't see any way of making either a standard nstoolbar look good on a HUD nor a way of customizing the background of a toolbar directly.

I am aware of the multitude of ways for creating a completely custom window, and use those in other circumstances. In this case, I want all of the good things that a window provides, but I just don't want transparency. Interestingly, I can change the background color, but not the alpha. Setting alpha values has no effect on the window.

Anyone solved this problem before?

skaffman
  • 398,947
  • 96
  • 818
  • 769
SG1
  • 1,155
  • 2
  • 9
  • 6

1 Answers1

0

Set the panel's content-view's (just click inside the panel to select it, not the titlebar) subclass to SGPanelView and make that SGPanelView with this implementation of a drawRect method of your class: SGPanelView, a subclass of NSView:

- drawRect:(NSRect)dirtyrect {
  [[NSColor blackColor] set];
  [NSBezierPath fillRect:[self bounds]];
}

Should work. If not working, try changing bounds to frame.


See http://developer.apple.com/library/mac/#documentation/cocoa/reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html for more information.

  • No can do - the toolbar is actually not part of the contentView's drawing. The toolbar draws over the window's background directly, not the content view. – SG1 Nov 15 '10 at 19:19
  • Use `[[window contentView] superView]` to get the window's view. Note that you've to alter the rect because it includes the title bar. –  Nov 15 '10 at 19:33