• 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: change NSView background color
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: change NSView background color


  • Subject: Re: change NSView background color
  • From: Scott Stevenson <email@hidden>
  • Date: Sat, 14 Apr 2007 19:37:49 -0700


On Apr 14, 2007, at 7:17 PM, Ahmet Taha Sakar wrote:

I have the following code:
- (void)drawRect:(NSRect)rect
{
   rect = [self bounds];
   [NSColor blueColor] set];
   [NSBezierPath fillRect: rect];
}

- (void) changeColor: (NSColor *)c
{
   [[NSColor blackColor] set];
   [NSBezierPath fillRect: [self bounds]];
}

with the drawRect method,  I get to have the NSView in blue color.
However,  I would like to change the color with an action so I created
changeColor method.  But I cant get it to change the color.  What am I
missing?  thnaks

There are a number of things that the code is missing. Basically, you need the color to be an instance variable, then call setNeedsDisplay:YES when the color changes.


All of the drawing (setting the color and filling) should take place only in the -drawRect: implementation. I think these might help you:

http://cocoadevcentral.com/d/intro_to_quartz/
http://cocoadevcentral.com/d/intro_to_quartz_two/

Best Regards,

     - Scott
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >change NSView background color (From: "Ahmet Taha Sakar" <email@hidden>)

  • Prev by Date: change NSView background color
  • Next by Date: Re: making an NSView with scrollbars "inactive"
  • Previous by thread: change NSView background color
  • Next by thread: CGEventKeyboardGetUnicodeString + modifier key
  • Index(es):
    • Date
    • Thread