FNGradientView – an NSControl for configuring color gradients

Written by David Frampton @ 7:26 am, December 10, 2010

FNGradientView

I always intended to make this available to other developers, and now here it is. FNGradientView provides a simple user interface and storage class for creating color gradients in Cocoa. It supports opacity, drag and drop, and view re-sizing. The FNGradient class (the data model) also supports NSCoding and NSCopying, so can be stored in an archive relatively easily.

All you should need is the FNGradient class, the FNGradientView class, and Color.h, and make sure you add QuartzCore.framework to your project.

Included is a demo app with an Xcode project that shows the FNGradientView as well as a preview which uses the control and displays the gradient animating through time.

You’ll have to look at the headers for documentation. It is intended that you create a custom view in interface builder, and set the class to FNGradientView. Then your app can access its FNGradient object, and ask for a color for a given fraction. Though programmatically creating the view should work just fine.

There are a few aspects to the code that seem odd to me now, two and a half years after I wrote it. But it should work on all systems above 10.5/Leopard, and may even work on 10.4, I did have a slightly older version running just fine on 10.4 so it shouldn’t take much.

I will read any emails, but may not respond, as this is just a free blob of code sent out into the wild for the benefit of any who should stumble upon it. I already have enough emails to respond to from my projects that make money!

But I do hope it is useful, and would appreciate any bug reports, even if I can’t find the time to respond. And I’d love to hear where it is used!

The official FNGradient license: Use any of the included code however you wish, but if it goes wrong, that’s your problem!

You can download the source and demo app here.









No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.