Create a two state button/widget

I want to have a two state button on my touch bar that can alternate it's color when pressed. So far I've only seen tutorials which request a state of an application but I actually only want to check the state of the button itself to change the button color.

Imprint | Privacy Policy