Skip navigation.
 
mlRe: How to associate a view with Color Panel
FROM : Todd Yandell
DATE : Thu Nov 04 20:50:02 2004

Hi,

NSColorPanel works by sending a changeColor: message to it's delegate,
which in your example is the CustomerView. Your view should then
respond to that message by changing the drawing color, and redrawing
whatever it is that should change color. For example, your
CustomerView.m file might look like this:

- (IBAction)colorButtonAction:(id)sender
{
       [[NSColorPanel sharedColorPanel] setDelegate:self];
}

- (void)changeColor:(id)colorPanel
{
   [self setNeedsDisplay:YES];
}

- (void)drawRect:(NSRect)rect
{
   [[[NSColorPanel sharedColorPanel] color] set];
   [[NSBezierPath bezierPathWithRect:rect] fill];
}

The colorButtonAction: message should be connected to your button in
Interface Builder. It opens a new NSColorPanel and sets it's delegate
to self. Then, whenever the user selects a new color, the NSColorPanel
sends it's delegate a changeColor: message, where you tell the view to
redraw itself. The drawRect: message then sets the selected color as
the drawing color, and draws a box (or whatever else you want).

That's it, hope this helps!

Todd

Related mailsAuthorDate
mlHow to associate a view with Color Panel Fei Li Nov 3, 19:51
mlRe: How to associate a view with Color Panel Todd Yandell Nov 4, 20:50
mlRe: How to associate a view with Color Panel M. Uli Kusterer Nov 5, 02:11