【问题标题】:How to disable a menuItem of a popUp button in macOS in Swift?如何在 Swift 中禁用 macOS 中弹出按钮的 menuItem?
【发布时间】:2017-05-10 15:00:15
【问题描述】:

我正在尝试禁用 macOS 应用程序中弹出按钮的 menuItem。我可以将状态设置为开或关(菜单项的复选标记),但我还没有找到将启用设置为 false(灰显)的方法。

func disableMyItem() {
    let myItem = actionButton.item(withTitle: "Test Item") // creating the NSMenuItem object
    myItem?.state = NSOffState // remove checkmark
    myItem?.isEnabled = false // has no effect

    print(myItem?.isEnabled) // "Optional(false)"
}

【问题讨论】:

标签: swift macos nsbutton


【解决方案1】:

如果您使用的是 Interface Builder,请取消选中 Attributes Inspector 中的“Autoenables”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 2017-07-22
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    • 2016-02-02
    • 1970-01-01
    相关资源
    最近更新 更多