NSToolbarItem 可用性基于 OS X 版本
我有一个可在多个版本的 OS X 上使用的应用程序。使 NSToolbarItem
仅对某些操作系统版本的用户可用的最佳方法是什么。当它不可用时,应该将其完全隐藏,而不仅仅是禁用。
为了简化,如何以编程方式从此(下面)菜单中删除工具栏项?
编辑: 我尝试在委托中覆盖 toolbarAllowedItemIdentifiers:
,如下所示:
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar {
NSLog(@"Toolbar requesting allowed items.");
NSMutableArray *array = [NSMutableArray array];
[array addObject:@"TPUpToolbarItem"];
[array addObject:@"TPDownToolbarItem"];
[array addObject:@"TPResetToolbarItem"];
[array addObject:@"TPSpeedToolbarItem"];
[array addObject:@"TPGroupToolbarItem"];
[array addObject:@"TPBackgroundToolbarItem"];
[array addObject:NSToolbarShowFontsItemIdentifier];
if (floor(NSAppKitVersionNumber) <= 1038) {
NSLog(@"Below Lion, adding Fullscreen item.");
[array addObject:@"TPFSToolbarItem"];
}
[array addObject:@"TPFlipHToolbarItem"];
[array addObject:@"TPFlipVToolbarItem"];
[array addObject:NSToolbarFlexibleSpaceItemIdentifier];
[array addObject:NSToolbarSpaceItemIdentifier];
[array addObject:NSToolbarSeparatorItemIdentifier];
[array addObject:NSToolbarShowColorsItemIdentifier];
[array addObject:NSToolbarPrintItemIdentifier];
return array;
}
所有其他工具栏项目都以正确的顺序显示,但是全屏项目位于最后,并且仍然存在。
提前致谢。
I have an application that will be available across multiple versions of OS X. What's the best way to make an NSToolbarItem
only available to users in certain OS versions. When it is not available, it should be completely hidden, not just disabled.
To simplify, how do I remove a toolbar item from this (below) menu programmatically?
Edit: I tried to override toolbarAllowedItemIdentifiers:
in the delegate like so:
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar {
NSLog(@"Toolbar requesting allowed items.");
NSMutableArray *array = [NSMutableArray array];
[array addObject:@"TPUpToolbarItem"];
[array addObject:@"TPDownToolbarItem"];
[array addObject:@"TPResetToolbarItem"];
[array addObject:@"TPSpeedToolbarItem"];
[array addObject:@"TPGroupToolbarItem"];
[array addObject:@"TPBackgroundToolbarItem"];
[array addObject:NSToolbarShowFontsItemIdentifier];
if (floor(NSAppKitVersionNumber) <= 1038) {
NSLog(@"Below Lion, adding Fullscreen item.");
[array addObject:@"TPFSToolbarItem"];
}
[array addObject:@"TPFlipHToolbarItem"];
[array addObject:@"TPFlipVToolbarItem"];
[array addObject:NSToolbarFlexibleSpaceItemIdentifier];
[array addObject:NSToolbarSpaceItemIdentifier];
[array addObject:NSToolbarSeparatorItemIdentifier];
[array addObject:NSToolbarShowColorsItemIdentifier];
[array addObject:NSToolbarPrintItemIdentifier];
return array;
}
All the other toolbar items show in the correct order, however the Fullscreen item is last, and still there.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了
-toolbarAllowedItemIdentifiers:
之外,不要忘记-toolbarDefaultItemIdentifiers:
。请尝试如下操作:--
请注意,如果您为工具栏设置了允许用户自定义,则可能需要删除应用程序首选项文件才能注意到工具栏设置中的更改。
Don't forget
-toolbarDefaultItemIdentifiers:
in addition to-toolbarAllowedItemIdentifiers:
. Try something like the following:--
Note that if you have allows user customization set for the toolbar, you may need to delete the apps pref file to notice a change in toolbar setup.
使用格式塔。
Use Gestalt.
@NSGod 就快到了。虽然他的其余代码可以工作,但 IB 似乎正在覆盖我的代码并添加全屏按钮。我必须将工具栏项目移出工具栏,然后通过添加以下方法手动将
NSToolbarDelegate
指向它:(up
,down
,等是IBOutlet
)@NSGod was almost there. While the rest of his code works, it appears IB is overriding my code and adding in the Fullscreen button anyway. I had to move the toolbar item out of the toolbar and then manually point the
NSToolbarDelegate
to it by adding this method: (up
,down
, etc. areIBOutlet
s)