使用Swift在MacOS中编写基本按键

2017-04-09  本文已影响0人  凡哥哥

代码如下:

import Cocoa


class ViewController: NSViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let bt = NSButton(frame: NSRect(x: 50, y: 50, width: 100, height: 30))
        bt.setButtonType(.momentaryPushIn)
        bt.bezelStyle = .roundRect
        bt.title = "test"
        bt.target = self
        bt.action = #selector(ViewController.click)
        self.view.addSubview(bt)

        // Do any additional setup after loading the view.
    }

   func click() {
        print("hello")
    }
    
    override var representedObject: Any? {
        didSet {
        // Update the view, if already loaded.
        }
    }


}
上一篇 下一篇

猜你喜欢

热点阅读