I am trying to recreate beautiful textured buttons, such as Finder, Safari and Transmission, on the toolbar. First, I started by simply dragging the Texture button to IB, etc. Everything works well, unless the user sets the toolbar to Text Only mode. When he presses the button, the icon and shortcut will be displayed on the toolbar. I remove the alles code and delegates from the toolbar to make sure this is not a problem with the code.
Then, to make sure I created a new project (no code at all), and I can reproduce the problem with a pure NSWindow with NSToolbar with one NSToolbarItem with NSButton in it.
Adding NSButtons with code:
- (NSArray*)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar { return [NSArray arrayWithObject:@"myToolbarMenu"]; } - (NSArray*)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar { return [self toolbarAllowedItemIdentifiers:toolbar]; } - (NSToolbarItem*)toolbar:(NSToolbar*)toolbar itemForItemIdentifier:(NSString*)str willBeInsertedIntoToolbar:(BOOL)flag { if ([str isEqualToString:@"myToolbarItem"] == YES) { NSToolbarItem* item = [[NSToolbarItem alloc] initWithItemIdentifier:str]; [item setView:[[NSButton alloc] init]]; [item setMinSize:NSMakeSize(50,50)]; [item setMaxSize:NSMakeSize(50,50)]; [item setLabel:@"Text"]; return [item autorelease]; } return nil; }
But it also has the same effect: when I click NSToolbarItem with NSButton in it in the "Text Only" mode, the toolbar itself makes it the "Icon and Text" mode.
Do you have any idea how I can make it work correctly, or maybe there is an alternative to creating beautiful looking toolbars like Safari etc.?
cocoa interface-builder nstoolbar
Ger teunis
source share