美文网首页
使用Swift在MacOS中编写基本按键

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

作者: 凡哥哥 | 来源:发表于2017-04-09 21:27 被阅读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.
            }
        }
    
    
    }
    

    相关文章

      网友评论

          本文标题:使用Swift在MacOS中编写基本按键

          本文链接:https://www.haomeiwen.com/subject/iikjattx.html