janehouse janehouse - 5 months ago 75
Objective-C Question

Customize NSToolbar - Disable "Use small size"

How do I disable the "Use small size" option in the toolbar? I am using Xcode 4.

(That's the option that appears when users go to customize the Toolbar.)

Answer

You could subclass NSToolbar, override -setSizeMode: and in your implementation call [super setSizeMode: NSToolbarSizeModeRegular];.

If you're instantiating the toolbar in Interface Builder then make sure you assign your subclass to the toolbar in the nib.

@implementation RKToolbar
- (void)setSizeMode:(NSToolbarSizeMode)aSizeMode
{
    [super setSizeMode:NSToolbarSizeModeRegular];
}
@end

This won't remove the checkbox from the customize panel but it will prevent it from doing anything.

There's not really a supported way to remove the checkbox. This does work but it's pretty hacky:

//in your NSToolbar subclass
- (void)runCustomizationPalette:(id)sender
{
    [super runCustomizationPalette:sender];

    NSWindow* toolbarWindow = [NSApp mainWindow];

    NSWindow* sheet = [toolbarWindow attachedSheet];

    for(NSView* view in [[sheet contentView] subviews])
    {
        if([view isKindOfClass:[NSButton class]])
        {
            if([[[(NSButton*)view cell] valueForKey:@"buttonType"] integerValue] == NSSwitchButton)
            {
                [view setHidden:YES];
            }
        }
    }
}
Comments