make a NSGradient from a given NSColor

212 views Asked by At

I have a function that paints a particular area with the NSColor that is passed to it. To give it a sort of 3D look I need to paint it with a gradient of the given color. Suppose NSColor is blueColor then the area should be painted with something like lightBlue to blueColor or something as such so that I can get a slight gradient effect.

So my question is how can I create NSColor which is lighter than the NSColor that is passed to the function.

1

There are 1 answers

1
Dmitry On BEST ANSWER

Look at the NSColor Class Reference "Changing the Color" section. There are several methods to make a new color form existing one:

– blendedColorWithFraction:ofColor:
– colorWithAlphaComponent:
– highlightWithLevel:
– shadowWithLevel:

Also you can create a new color with RGB components calculated from your existing color (or HSB components) with

+ colorWithCalibratedHue:saturation:brightness:alpha:
+ colorWithCalibratedRed:green:blue:alpha: