Setting a Window’s Appearance
You usually configure most aspects of a window’s appearance in Interface Builder. Sometimes, however, you may need to create a window programmatically, or alter its appearance after it has been created.
Setting a Window’s Style
The peripheral elements that a window displays define its style. Though you can’t access and manipulate them directly, you can determine at initialization whether a window has them by providing a style mask to the initializer. There are four possible style elements, specifiable by combining their mask values using the C bitwise OR operator:
A title bar
A close button
A minimize button
A resize bar, border, or box
You can also specify
NSBorderlessWindowMask, in which case none of these style elements is used.
Typically, you set a window’s appearance once, when it is first created. Sometimes, however, you want to enable or disable a button in the title bar to reflect changed context. To do this, you first retrieve the button from the window using the
NSWindow method and then set its enabled state, as in the following example.
NSButton *closeButton = [window standardWindowButton:NSWindowCloseButton];
The constants required to access standard title bar widgets are defined in the API reference for
Setting a Window’s Color and Transparency
You can set a window’s background color and transparency using the methods
You can set a window’s background color to a non-opaque color. This does not affect the window’s title bar; it only makes the background itself transparent if the window is not opaque, as illustrated in the following example.
[myWindow setOpaque:NO]; // YES by default
NSColor *semiTransparentBlue =
[NSColor colorWithDeviceRed:0.0 green:0.0 blue:1.0 alpha:0.5];
Views placed on a non-opaque window with a transparent background color retain their own opacity. If you want to make the entire window (including the title bar and views placed on the window) transparent, you should use
Setting a Window’s Color Space
You can set a window’s color space using
setColorSpace: and can retrieve the window’s current color space using
NSColorSpace objects for use with
setColorSpace: may be obtained using the class methods documented in NSColorSpace Class Reference.
Setting a Window’s Content Border Thickness
Beginning in OS X version 10.5, windows automatically have a textured gradient applied to their backgrounds. The area on which the gradient is drawn is determined automatically. At times, however, this may not work correctly. If your window does not look correct with automatic gradient calculation, disable it by calling
setAutorecalculatesContentBorderThickness:forEdge: with a value of
NO and the edge to disable automatic calculation for. The value of this property may be accessed using the method
You can also set and access the content border thickness manually using