Size of drawer in IB?

Hi all,

How can I change the size of a drawer in IB? The default size is much bigger than I need it to be. I have tried adjusting the height attributes but it doesn’t seem to make any difference when I run the XCode application.


Hi :slight_smile:

In IB, you must select the “NSDrawer” object in the “Instances” tab of the nib window.
Display the size pane info and change the sizes as you want/needs.

To test the “Drower”, make a simple button in the window main, and connect-it (control drag) to the “NSDrawer” object in the “Instances” tab of the nib window, then, connect with the “toggle” action in the “Info” window, lastly, “command + R” to test the interface in IB.

To know how to handle the “Drawer” by the code, look at the “Drawer” exemple, provided with the “Dev Tools”, at this path:
“/Developer/Examples/AppleScript Studio/Drawer/”


If a drawer is on the right or left of its parent window, you should not change its height, only its width. It tends to look weird if it falls short.

In any case, drawers on the right or left sides of windows cannot have their content height values altered in Interface Builder. Conversely, drawers on the bottom of windows cannot have their content width values altered in IB. In both cases, these values are calculated automatically.

Edit about calcuation: The height is calculated from other values. Change the offset of the drawer, for example, and the size changes. Play around to see what does what, but really, it’s generally not done because it looks odd.

Thaks for the replies guys :slight_smile:

I did try the size attributes but they didn’t seem to make any difference. I tried again after reading your post and it has now worked. Weird! I had already written some code behind an on clicked handler to toggle the drawer opened and closed, but have now deleted this in favour of your much neater solution of connecting a button to the drawer’s toggle input.

I did adjust the offset actually, as the left shadow of the drawer extended further than the edge of the window, so it looked a bit weird. The drawer is on the bottom of the window so I brought the left and right edges in by 15 pixels each, and it looks great.

Thanks again!


How was this not automatically set in IB? The default offset for a drawer is 15 pixels.

The right hand side was already set to 15 but the left side was 0. I may have changed it by mistake while I was trying to figure out how to resize the drawer.

Hi motorollin & Mikey-San :slight_smile:

Motorollin, generally, when you create the drawer window, you build three different objects at the same time (see at the “Instances” tab in the “nib” window):

  • The parent window for the drawer (class “NSWindow”)
  • The drawer object itself (class “NSDrawer”)
  • The drawer contents view (class “NSView”)

The drawer object is never displayed in IB, it is generated dynamically only when the nib resources are launched and charged in memory (when you test the interface in IB for exemple).

So, I think that you had tried to change the size properties of the “drawer contents view” (displayed in IB), and not directly the “drawer” object itself (only selectable in the “Instances” tab), this is why, in my opinion, your changes did not work at the first time.

Now, if you change the “drawer contents view” dimension sizes, you must to adapt the dimension sizes of the “drawer” itself. In the same case, if you change the “drawer” dimension sizes, you must to make the corresponding changes to the “drawer contents view”.

It is a simple logical rule, which is not always obvious for those which discover the “drawer” for the first time. and I know what I speak :wink:

Unfortunately, I does not know automatic method to carry out this double size operation on the “drawer” and his “contents view” , which can be sometimes a little (much) laborious !

Bye… :slight_smile:

You absolutely can see the NSDrawer object in Interface Builder. You can’t see its drawn representation, but the object itself is there the moment you instantiate it. This is an important distinction to make, because when we talk about “objects” in Interface Builder, we’re talking about Cocoa objects, not whether or not they’re drawn on the screen. For example:

Bam, I now have an NSDrawer object that I can talk to. It can’t be drawn anywhere yet, because it has no parent window, but it certainly exists. This is how Interface Builder works, too, except that you can see the object itself in the nib window.

It sounds pedantic, but like I said, it’s important to understand because it provides necessary insight into how the system works, and it makes developer communication easier.

As for why the offset wasn’t right: Yeah, you probably changed it accidentally. It’s easy to do. I do it all the time.