I´m trying to make a simple colored NSButton. It seems there are two problems i don´t get solved:
1. How can I stop the button from being highlighted when clicked? I set a red background to my button:
When clicked, the color disappears:
How could I keep the backgroundcolor, even when the button is clicked?.
- How could I remove the gray border?
I tried different things:
class myButton: NSButton {
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
self.wantsLayer = true
self.isBordered = false
self.title = "hello"
self.setButtonType(NSMomentaryLightButton)
self.layer?.cornerRadius = 0
self.layer?.borderWidth = 0
self.layer?.masksToBounds = false
self.layer?.backgroundColor = NSColor.red.cgColor
self.appearance = NSAppearance(named: NSAppearanceNameAqua)
}
}
Of which nothing has an effect so far. Thank you everyone for help and ideas.
// UPDATE
I´m achieving my goal adding this to the code:
let color = NSColor.red
color.setFill()
NSRectFill(dirtyRect)
Unfortunately after that, the button´s title is no longer shown. So maybe a question of how to show button´s title after NSRectFill ?