1

我有一个应用程序,其标准NSWindow包含 aNSToolbar和几个NSToolbarItems 作为首选项。s 设置为可选,并使用包含的NSToolbarItem“模板”作为其名称的一部分,以获得漂亮的系统渐变效果。

However, when the NSToolbarItemis selected, the selection does not change the background of the text.

每个都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在 Interface Builder 中的所有配置:

ib

而它NSToolbar本身:

工具栏

4

1 回答 1

0

作为我的 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;
}
于 2014-05-22T19:10:39.800 回答