How to disable a button of a NSToolbar of macOS X in Swift?

最后都变了- 提交于 2020-01-04 06:10:53

问题


I would like to enable and disable programmatically a toolbar item (a button) of a NSToolBar in macOS. I tried to create an outlet to ViewController control-dragging but Xcode don't accept the drop. How can I do this?

I read this question about a similar question with Objective-C answers but I'm a beginner and can't understand well how to do this in Swift.


回答1:


Implement the delegate method

override func validateToolbarItem(_ item: NSToolbarItem) -> Bool

You can distinguish the items for example by the itemIdentifier and return true to enable and false to disable the item

The documentation provides an example.



来源:https://stackoverflow.com/questions/44577092/how-to-disable-a-button-of-a-nstoolbar-of-macos-x-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!