RE: Making custom looks for controls
RE: Making custom looks for controls
- Subject: RE: Making custom looks for controls
- From: "Josh Ferguson" <email@hidden>
- Date: Tue, 31 May 2005 09:59:46 -0500
- Thread-topic: Making custom looks for controls
Juan,
For most controls you'll actually have to override the corresponding
Cell classes in addition to a control class. Without going into too much
detail (which can be found in the "Controls and Cells" documentation
located at
file:///Developer/ADC Reference Library/documentation/Cocoa/Conceptu
al/ControlCell/index.html) a control typically has a Cell class
associated with it. The NSCell subclass is what's responsible for
actually drawing itself and responding to events in a control - but the
NSControl subclass manages the Cell by telling it when to respond to
events and when to draw itself.
In order to override the drawing on an NSCell (and hence, the appearance
of the control), you should override the following methods in your
subclass:
-(void)drawWithFrame:inView:
-(void)drawInteriorWithFrame:inView:
Depending on the control/cell you're overriding, you may also have other
methods to override (such as NSSliderCell's drawKnob: method). Once
you've subclassed the cell, you'll probably want to create a subclass of
the control to inform it to use your custom NSCell subclass. This is
achieved by subclassing the Control class you're replacing and
overriding +(Class)cellClass. Your cellClass method would look something
like this:
+(Class)cellClass
{
return [MyCellClass class];
}
There are also some exceptions to this. Notably, NSScroller and
NSColorWell do all of the drawing in the NSController subclass and don't
make use of an NSCell subclass.
Josh Ferguson
-----Original Message-----
From: cocoa-dev-bounces+josh=email@hidden
[mailto:cocoa-dev-bounces+josh=email@hidden] On Behalf
Of August Trometer
Sent: Friday, May 27, 2005 1:23 PM
To: Cocoa
Subject: Re: Making custom looks for controls
Most of that stuff happens in the drawRect: method. Subclass the
control and overwrite drawRect: to draw the control however you'd like.
August
On May 27, 2005, at 1:12 PM, Jose Pertierra wrote:
> Hello,
>
> Can anyone point me in the right direction as to how create custom
> looking controls? For example, Apple Shake has all the standard
> controls (PopUps, etc) but they look completely different from the
> standard aqua look.
>
> My shot in the dark is to create new control classes which
> overwrite whatever the draw function is. If this is the right way
> to do it, what kind of draw functions should I be using in this
> draw function?
>
_______________________________________________
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
_______________________________________________
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