1.5 NSButton
NSButton是Cocoa中用来作为点击响应的控件。常见的可分为文本类型按钮与图片类型的按钮
1.5.1 基本声明
var plainButton: NSButton!
override func loadView() {
self.view = NSView(frame: NSRect(x: 0, y: 0, width: 500, height: 300))
}
private func initView(){
mView = NSView(frame: NSRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height))
plainButton = NSButton(frame: NSRect(x: (self.view.frame.width / 2) - 25, y: self.view.frame.height - 30, width: 50, height: 29))
plainButton.alignment = .center
plainButton.setButtonType(NSButton.ButtonType.momentaryPushIn)
plainButton.bezelStyle = .roundRect
plainButton.toolTip = "This is a notice."
plainButton.title = "Plain"
plainButton.target = self
plainButton.action = #selector(plainListener)
self.view.addSubview(plainButton)
}
说明:使用NSButton创建的过程中需要注意的是setButtonType() 是用来设置NSButton按下去的效果类别,bezelStyle