0
我想定製myButton,以便在mouseDown發生時更改背景顏色,並在調用mouseUp時返回默認顏色。自定義NSButton。點擊時如何改變顏色
override func mouseDown(theEvent: NSEvent) {
super.mouseDown(theEvent)
self.bgColor = NSColor(hex: 0x4A7AA1)
self.textColor = NSColor.darkGrayColor()
self.needsDisplay = true
self.mouseUp(theEvent)
}
override func mouseUp(theEvent: NSEvent) {
self.textColor = NSColor.whiteColor()
self.bgColor = NSColor(hex: 0x6AAFE6, alpha: 0.95)
}
我試着運行這段代碼,但鼠標關閉時所有視圖都沒有重繪。我如何在myButton上執行此功能:NSButton類?