NSToolbar特殊区 [英] NSToolbar special area

查看:223
本文介绍了NSToolbar特殊区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢尝试完全接管NSToolbar所在的区域,因此我可以自己设置自定义控件,视图和背景。使用此区域的优点是:

I like to try to completely take over the area where the NSToolbar resides so I can put my own custom controls, views and background. The advantages of using this area are:


  • 任何滑动面板显示在工具栏区域下方,而不是标题栏。

  • 在Lion中,当鼠标位于屏幕顶部时,工具栏区域随同菜单栏一起下来。

我已经尝试使用无边框窗口,并在其中实现自己的自定义视图,但不幸的是,我失去了上述优势,还有一些其他的小问题。

I have tried using a borderless window, and implementing my own custom views within it but unfortunately I lose the above advantages as well as having a few other minor problems.

我当前的方法是使用未记录的方法'_toolbarView'与NSToolbar和添加我的自定义视图到其子视图。这工作正常,因为我可以关闭工具栏自定义。不幸的是,工具栏的大小用该工具栏中的项目初始化。有没有人知道如果我可以改变工具栏的大小,而不添加一个假的ToolbarItem?

My current method is to use the undocumented method '_toolbarView' with the NSToolbar and add my custom view into its subviews. This works fine as I can turn off toolbar customisation. Unfortunately, the size of the toolbar is initialised with the items within that toolbar. Does anyone know if I can change the size of toolbar without adding a fake ToolbarItem?

也许还有一个更好的方式这样做,我目前不知道。
感谢任何建议和意见。

Maybe there's also a better way of doing this that I am currently unaware of. Thanks for any suggestions and comments.

推荐答案

不需要使用任何未记录的API。只需创建一个工具栏项目与自定义视图:

No need to use any undocumented APIs. Just create a toolbar item with a custom view:

- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag {
    NSToolbarItem *item = [[[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier] autorelease];
    …
    [item setView:myCustomToolbarView];
    …
}

您可以使用项目的 minSize maxSize 属性(例如在 NSWindowDelegate code> -windowDidResize:)。

You can control your custom toolbar’s size using the item’s minSize and maxSize properties (e. g. in your NSWindowDelegate’s -windowDidResize:).

记住还要更新工具栏显示模式, / p>

Remember to also update the toolbar display mode so it doesn't show item labels:

[toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];

这篇关于NSToolbar特殊区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆