Change NSButton's background color on highlight

牧云@^-^@ 提交于 2019-12-05 06:37:55

In the end, I solved it by subclassing NSButtonCell and overwriting

- (void) highlight:(BOOL)flag withFrame:(NSRect)cellFrame inView:(NSView*)controlView

to make the changes I wanted (changing controlView.layer.backgroundColor based on flag)

You will need to subclass your NSButton and override its mouseDown: and mouseUp: events, change the color of your NSButton in these events.

Swift version of Cobbal's answer:

override func highlight(_ flag: Bool, withFrame cellFrame: NSRect, in controlView: NSView) {
        //do nothing, to disable highlight
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!