Drawers

Drawers provide additional window space for an application’s interface, and can easily be tucked away from view when not in use. Drawers are ideal for controls that are frequently used, but don’t need to be visible at all times. Figure 3-9 shows an example of a drawer in Mail.

The mailboxes drawer from Mail.app
Figure 3-9. The mailboxes drawer from Mail.app

The class NSDrawer defines the behavior of drawers. Interface Builder provides the ability to create drawers and attach them to windows. The window that a drawer is associated with is called the parent window . Like windows, drawers contain a view hierarchy. The top-level view of this hierarchy is the drawer’s content view . NSDrawer objects in Interface Builder have outlets connected to the drawer’s parent window and content view. Alternatively, you can set a drawer’s parent window of a drawer with the method setParentWindow: and set the content view with setContentView:.

When a drawer opens or closes, it slides from an edge of the parent window. Drawers have a preferred edge of the parent window on which they try to open. Without sufficient room between the preferred edge and the adjacent edge of the screen display, the drawer opens on the opposite side of the window. The preferred edge may be any side of the window: top, bottom, left, or right. You can access this property with setPreferredEdge: and preferredEdge. In these methods, the edge is represented ...

Get Cocoa in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.