代码如下:
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.
}
}
}
网友评论