我有一个子类 NSButton 的自定义按钮。我想在按钮处于按下状态时更改内容色调颜色。这就是我所拥有的:
open override func mouseDown(with event: NSEvent) {
// update contentTintColor
contentTintColor = contentTintColorPressed
// call super to inherit the click action
super.mouseDown(with: event)
// for some reason mouseUp doesn't trigger if I call super, so I have to override and manually call mouseUp
self.mouseUp(with: event)
}
这样做的结果是内容的色调颜色变成了背景颜色,因此按钮内容是不可见的。为什么只有当我将光标拖到按钮外时 contentTintColor 才会更新?演示