我有一个带有标准NSWindow的应用程序,它包含一个带有几个NSToolbarItem的NSToolbar作为首选项。NSToolbarItem被设置为可选择的,并使用包含的“模板”作为其名称的一部分,以获得良好的系统梯度效果。
但是,当选择NSToolbarItem时,所选内容不会更改文本的背景。
每个NSToolbarItem标记为可选,我的NSToolbarDelegate只实现这两个方法:
-(NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar{
NSMutableSet *toolbarSet = [NSMutableSet set];
for (NSDictionary *prefItem in _preferenceItems){
[toolbarSet addObject:[prefItem objectForKey:@"toolbarIdentifier"]];
}
return [toolbarSet allObjects];
}
-(NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar{
NSMutableSet *selectableSet = [NSMutableSet set];
for (NSDictionary *prefItem in _preferenceItems){
[selectableSet addObject:[prefItem objectForKey:@"toolbarIdentifier"]];
}
return [selectableSet allObjects];
}下面是我所看到的;注意文本周围的灰色框:

与Safari的“首选项”窗口相反:

接口生成器中所有NSToolbarItem的配置:

而NSToolbar本身:

发布于 2014-05-22 19:10:39
作为我的NSToolbarDelegate / NSWindowController设置的一部分,我设置:
[[[self window] contentView] setWantsLayer:YES];评论这一行解决了这个问题。
在以下方面:
-(void)awakeFromNib{
NSDictionary *zendeskItem = @{@"name" : @"Zendesk Accounts",
@"toolbarIdentifier" : @"zendesk"};
NSDictionary *toolItem = @{@"name" : @"Tools",
@"toolbarIdentifier" : @"tools"};
NSDictionary *supportItem = @{@"name" : @"Support",
@"toolbarIdentifier" : @"support"};
NSDictionary *healthItem = @{@"name" : @"Health",
@"toolbarIdentifier" : @"health"};
NSDictionary *aboutItem = @{@"name" : @"About",
@"toolbarIdentifier" : @"about"};
_preferenceItems = [NSArray arrayWithObjects:zendeskItem, toolItem, supportItem, healthItem, aboutItem, nil];
[[self window] setContentSize:[_zendeskView frame].size];
[[[self window] contentView] addSubview:_zendeskView];
//[[[self window] contentView] setWantsLayer:YES];
currentViewTag = 1;
}https://stackoverflow.com/questions/23699887
复制相似问题