How to disable a button of a NSToolbar of macOS X

2019-07-15 15:26发布

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条回答
混吃等死
2楼-- · 2019-07-15 15:53

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.

查看更多
登录 后发表回答