Parmanoir

Changing the background color of an NSButton

If you want to color or visually change one of your controls, the easiest way to do it is with Core Image. In Interface Builder, click wants Core Animation Layer, and add content filters.

Image:Changing background color of NSButton.png

This one uses Color Monochrome to color the button. In Dynamic overloading : sample code, I used Color Matrix but strangely it's not available in my version of IB. Well, you can always set it up in code. It's better than overloading all NSButtons' drawRect — that's quite overkill to color just one button. :)

Gunnar
2009 04 26

Neat stuff. I don't think I'd have found this on my own. I think it's ok for some button styles, but I wonder if there's a way to tweak it so it doesn't color the grey pixels around anti-aliased text. Thanks for sharing.

Brian Palmer
2011 05 02

thanks, this took me all day to find. apple does not make things easy

Mike Pitter
2018 09 04

This is really a fantastic article about changing image background color. In this post, I learn a lot from your blog. Many many thanks for your tutorial.


Follow me on Twitter
Planet Cocoa
Cocoa.fr

2011 02 22Distance field
2010 07 202Binding through NSApp
2010 05 122Forwarding invocations
2010 02 272Core Image black fringes
2010 02 21Quickest Way to Shell
2010 02 08Who's calling ?
2009 09 2138 ways to use Blocks in Snow Leopard
2009 08 182Bracket Mess
2009 08 124Taming JavascriptCore within and without WebView
2009 04 15Debugging with Activity Monitor
2009 03 25How Core Image Color Tracking works
2009 03 1510Custom NSThemeFrame
2009 03 10Which framework is running ?
2009 03 074CoreUI can paint pretty big
2009 02 18Localization with functions
2009 01 30Did you forget to nest alloc and init?
2009 01 16JSCocoa on the iPhone
2009 01 11Mixing WebView and JavascriptCore
2009 01 09Badge overflow
2009 01 09Find your Garbage Collection leaks with Instruments

Powered by MediaWiki