• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to associate a view with Color Panel
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: How to associate a view with Color Panel
      • From: "M. Uli Kusterer" <email@hidden>
References: 
 >How to associate a view with Color Panel (From: Fei Li <email@hidden>)

  • Prev by Date: Re: Meaning of NSFont italicAngle?
  • Next by Date: New Spotlight Info
  • Previous by thread: How to associate a view with Color Panel
  • Next by thread: Re: How to associate a view with Color Panel
  • Index(es):
    • Date
    • Thread