【问题标题】:NSButton programmatically Push on Push off TypeNSButton 以编程方式 Push on Push off 类型
【发布时间】:2018-01-10 20:10:41
【问题描述】:

我通过以下方式在 Swift MacOS 中创建按钮:

        let feld = NSButton()
        feld.frame = CGRect(x: 900+30*h, y: 20, width: 22, height: 22)
        feld.image = NSImage(named: NSImage.Name("Mulleimer"))
        feld.target = self
        feld.action = #selector(ButtonTest)
        self.view.addSubview(feld)

现在我想将按钮的样式更改为“Push on Push off”。 我试过这样的东西:

feld.setButtonType(NSButton.???)

它永远不会起作用。我知道答案应该在:

https://developer.apple.com/documentation/appkit/nsbutton/1524983-setbuttontype

但不知道,我只是不明白如何将其转换为工作代码。有人可以帮忙吗?谢谢!

【问题讨论】:

    标签: swift macos nsbutton programmatically


    【解决方案1】:

    请使用代码完成。

    输入setButtonType( 和点,你会看到

    原来如此

    feld.setButtonType(.pushOnPushOff)
    

    PS:你导入AppKit了吗?

    【讨论】:

      猜你喜欢
      • 2020-10-02
      • 2013-12-31
      • 2019-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多