0

I made a custom view for my button in the menu bar. Since I added it as subview, it got rid of the effect when the button got clicked like here with the battery:

enter image description here

Now I saw that I can override the mouseDown effect und mouseUp to do this effect manually. Does anyone know how I could add this kind of effect?

Edit: for example, it would solve my problem, if I knew how to paint the background of my rectangle in my custom NSView

Cemal K
  • 96
  • 8

1 Answers1

0

Ok, I actually got it thanks to the help of this question: Best way to change the background color for an NSView

override func mouseDown(with theEvent: NSEvent) {
    switcher = true
    needsDisplay = true
}

override func mouseUp(with theEvent: NSEvent)
{
    switcher = false
    needsDisplay = true
}

override func draw(_ dirtyRect: NSRect) {

    [do the usual thing]

    if (switcher == true)
    {
    // color picked the color of the normal mouseDown event
    let c1  = NSColor(calibratedRed: 48.0/255.0, green: 91.0/255.0, blue: 178.0/255.0, alpha: 1.0)
        c1.setFill()
        self.frame.fill()
        myrect?.fill()
        NSColor.clear.setFill()
        [do the usual thing]
    }
}
Cemal K
  • 96
  • 8