Re: Newbie question on NSControl
Re: Newbie question on NSControl
- Subject: Re: Newbie question on NSControl
- From: "John C. Randolph" <email@hidden>
- Date: Fri, 4 Jan 2002 15:38:11 -0800
On Friday, January 4, 2002, at 02:16 PM, Rob Crawford wrote:
>
Thanks in advance!
>
I would like to create a custom control that draw's
>
differenctly depending
>
on the value that is in the control. This is my header file:
>
>
@interface ExampleView : NSControl
>
{
>
}
>
- (void)drawRect:(NSRect)aRect;
>
>
Question 1.
>
What else do I need to override so when the value gets changed
>
the drawRect
>
method gets called?
In the method that changes the value in question, call
-setNeedsDisplay:, e.g:
- (void) setColor:(NSColor *) aColor
{
if (myColor) // assume this is an iVar..
{
if (aColor == myColor) // bail if there's nothing to do..
return;
[myColor release];
}
myColor = [aColor retain];
[self setNeedsDisplay:YES];
}
>
Question 2.
>
How can I get IB to let me put in the default value for this
>
control so that
>
it will draw correctly the first time?
Well, if you're subclassing an existing control that has a
value, like an NSTextField or an NSSlider, you can edit them
just like always in IB. (i.e, if you're subclassing NSSlider,
drag a slider off the palette, set it like you want, and use the
"custom subclass" inspector to indicate that you actually want
an instance of your subclass.)
If you're talking about initializing values that you're
creating, it's easiest to have some object in the nib implement
an -awakeFromNib method, and set the values from there.
-jcr
[Objc retain];