1

In MacOS there is a simple App called Calculator, that I would like to recreate using Swift for learning purposes. A button like the plus button on the calculator has two images associated with it, one when the button is up and one when the button is down, as seen on the images below.

enter image description here

enter image description here

As you can see, when the + button is pressed down, its image changes to a darker orange color and the text gets a dark grey color. My question is: How to implement this button behavior?

Is it possible to do it with NSButton (and if so how)? or is it easier to implement it using CALayer? Or maybe there is some other way that I have not thought of?

Bob Ueland
  • 1,804
  • 1
  • 15
  • 24

1 Answers1

0

You should be able to use a single image and configure it in code or in your asset catalogue to be a "template image". That means the shape is taken into consideration, much like a stamp, and the stamped-out area is filled with color dynamically. That means you don't have to provide a white and dark gray/black variant. One variant will suffice, usually black to see the lines well, and the rest can be configured through.

See the SO question "How to NOT highlight the NSButton's template image when clicked?" for details about the setup: How to NOT highlight the NSButton's template image when clicked?

ctietze
  • 2,805
  • 25
  • 46