Re: How to associate a view with Color Panel
Re: How to associate a view with Color Panel
- Subject: Re: How to associate a view with Color Panel
- From: Todd Yandell <email@hidden>
- Date: Thu, 4 Nov 2004 13:50:02 -0600
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:
<x-tad-bigger>- (</x-tad-bigger><x-tad-bigger>id</x-tad-bigger><x-tad-bigger>)sender
{
[[NSColorPanel sharedColorPanel] setDelegate:</x-tad-bigger><x-tad-bigger>self</x-tad-bigger><x-tad-bigger>];
}
- (</x-tad-bigger><x-tad-bigger>id</x-tad-bigger><x-tad-bigger>)colorPanel
{
[</x-tad-bigger><x-tad-bigger>self</x-tad-bigger><x-tad-bigger> setNeedsDisplay:</x-tad-bigger><x-tad-bigger>YES</x-tad-bigger><x-tad-bigger>];
}
- (</x-tad-bigger><x-tad-bigger>void</x-tad-bigger><x-tad-bigger>)drawRect:(NSRect)rect
{
[[[NSColorPanel sharedColorPanel] color] set];
[[NSBezierPath bezierPathWithRect:rect] fill];
}
</x-tad-bigger>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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden