8

I'd like to make an NSToolbarItem with a custom image which toggles between Black and Blue, like the icons at the top right of Xcode 5's main window.

Peter Hosey suggested in this answer that it was as simple as setting the image to be a template, but I haven't found that to be the case. I set it to a template image, and that causes it properly render the dark gray gradient, but it doesn't render in blue when toggled.

I uploaded a very simple example of what I've done, here. If someone could tell me how to change it to light up the NSToolbarItem in blue, as Xcode does, then I'd very much appreciate it.

Community
  • 1
  • 1
ArtOfWarfare
  • 20,617
  • 19
  • 137
  • 193

1 Answers1

8

You mostly have everything you need in place, with the exception of providing an NSButton object using the style NSTexturedRoundedBezelStyle, with which you’ve associated your image.

enter image description here

modified example project here

OS X Human Interface Guidelines | Window-Frame Controls

l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • Hi - There was just one small problem I had with the project you uploaded. Placing two of those buttons side by side would have them be spread way apart. To fix it, I just clicked on the toolbar item (not the button or button cell that it contains), went to the measurement inspector, and changed the maximum width it was allowed to have. – ArtOfWarfare Dec 31 '13 at 16:16
  • I'd like to point out that there seems to be a bug and you can't use xcassets with this technique... it seems you have to use raw images. – ArtOfWarfare Dec 31 '13 at 18:43