0

I have a custom button that subclasses NSButton. I want to change the content tint color when the button is in pressed state. This is what I have:

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)
}

The result of this is the content tint color becomes the backgroundColor, so the button content is invisible. Why is that the contentTintColor updates only when I drag my cursor outside of the button? demo

manchiu
  • 3
  • 2

1 Answers1

-1

Programmatically you can change like this:

@IBOutlet weak var button: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()

    // Change button text color when tapping is on hold.
    button.setTitleColor(UIColor.red, for: .highlighted)
}

If you have custom UIButton class, use like this:

self.setTitleColor(UIColor.red, for: .highlighted)
Egzon P.
  • 4,498
  • 3
  • 32
  • 31
  • This doesn't work for me since I'm using NSButton. I want to manipulate the title color using the contentTintColor attribute. – manchiu Dec 24 '20 at 19:54
  • Hi Manchiu, let me know once you find an answer, would like to know how to do for NSButton. – Egzon P. Dec 29 '20 at 21:23