I am writing a cocoa application which has a NSWindow. I want to change the background color of the window to a specific color. But the window properties in the inspector only provide "Textured Window" alternative. How can I make the color of the window as desired?
相关问题
- NSOutlineView drag line stuck + blue border
- iphone sdk see size of local file (one created
- How can you detect the connection and disconnectio
- QuickLook Plugin Failing with sandboxing error
- NSTextField font styling resets when selected
相关文章
- Xcode: Is there a way to change line spacing (UI L
- Converting (u)int64_t to NSNumbers
- “getter” keyword in @property declaration in Objec
- NSMenuItem KeyEquivalent “ ”(space) bug
- Why are my UIView layer properties not being set w
- Detect if cursor is hidden on Mac OS X
- NSNumberFormatter doesn't allow typing decimal
- Is subclassing NSNotification the right route if I
Try calling the instance method setBackgroundColor: with a color on your window instance. What's in a name.. ;)
Like this:
The simplest way to change window background is to set it directly in your .xib file.
No code at all:
You have to subclass NSWindow in order to change the background and then override the implementation for
As an example see Mat Gemmell's HUDWindow: http://mattgemmell.com/2006/03/12/hudwindow
As long as you only want to change the background color of the content area, not the frame and toolbar, you don't need to subclass
NSWindow
. What you do need to do is subclassNSView
and make your custom view draw your desired color, then set an instance of that class as the window's content view.Alternatively, you may be able to get away with setting a borderless
NSImageView
orNSColorWell
as the content view, but I'm not sure that Apple means for those to have subviews. If not, you'd have to leave your window empty.That said, you should be really sure that a custom background color is appropriate. Almost always, it's not, and you should stick with the Aqua or HUD appearance.