- (void)
setUpToolbar {
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@
"AppToolbar"];
[toolbar
setAllowsUserCustomization:NO];
[toolbar
setAutosavesConfiguration:NO];
[toolbar
setDisplayMode:NSToolbarDisplayModeIconAndLabel];
[toolbar
setSizeMode:NSToolbarSizeModeSmall];
[toolbar
setDelegate:self];
[self.window
setToolbar:toolbar];
}
//所有的item 标识
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar {
return @[@
"FontSetting",@
"Save"];
}
//实际显示的item 标识
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar {
return @[@
"FontSetting",@
"Save"];
}
//根据item 标识 返回每个具体的NSToolbarItem对象实例
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag {
NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier];
if ([itemIdentifier isEqualToString:@
"FontSetting"]) {
[toolbarItem
setLabel:@
"Font"];
[toolbarItem
setPaletteLabel:@
"Font"];
[toolbarItem
setToolTip:@
"Font Setting"];
[toolbarItem
setImage:[NSImage imageNamed:@
"FontSetting"]];
toolbarItem.tag = kFontToolbatItemTag;
}
else if ([itemIdentifier isEqualToString:@
"Save"]) {
[toolbarItem
setLabel:@
"Save"];
[toolbarItem
setPaletteLabel:@
"Save"];
[toolbarItem
setToolTip:@
"Save File"];
[toolbarItem
setImage:[NSImage imageNamed:@
"Save"]];
toolbarItem.tag = kSaveToolbatItemTag;
}
else {
toolbarItem = nil;
}
[toolbarItem
setM
inSize:CGSizeMake(
25,
25)];
[toolbarItem
setMaxSize:CGSizeMake(
100,
100)];
[toolbarItem
setTarget:self];
[toolbarItem
setAction:@selector(toolbarItemClicked:)];
return toolbarItem;
}
- (void)toolbarItemClicked:(NSToolbarItem *)toolbar {
NSLog(@
"-------%@", toolbar.itemIdentifier);
}