PDA

View Full Version : NSSlider customizing ?




Mark FX
Jan 21, 2012, 02:35 PM
Hi everyone

I have been getting to grips with Objective-C and Xcode over the past six months, after coming
from other languages.

I wanted to know if anyone has help for customising the NSSlider, I see from the doc's that the
NSSlider class has no methods, for changing its appearance, specifically I wanted to change
the slider knob image, and possibly the slider image color.

I have found resources on the Web for the iOS UISlider customising, but none for the OSX
NSSlider, any pointers to other resources would be great, or a resource for custom controls.

Many Thanks

Regards Mark



JoshDC
Jan 21, 2012, 02:55 PM
You need to subclass NSSliderCell instead, and tell your NSSlider to use the subclass. It should be fairly easy to pick out what methods you need to override from the NSSliderCell class reference.

Mark FX
Jan 22, 2012, 01:28 PM
Thanks for the advise Josh.

I think the main problem with the NSSlider class is, that it has no methods to
change its image's appearance, but I shall keep trying.

Regards Mark

jiminaus
Jan 22, 2012, 01:57 PM
Thanks for the advise Josh.

I think the main problem with the NSSlider class is, that it has no methods to
change its image's appearance, but I shall keep trying.

Regards Mark

You did notice the difference right? NSSlider verses NSSliderCell. This is a common pattern in Cocoa. The control class is just a container for a cell and it's actually the cell that does the drawing.

You can change the knob but subclassing NSSliderCell and overriding the - (void)drawKnob:(NSRect) method.

Mark FX
Jan 25, 2012, 01:55 PM
Thanks jiminaus, for steering me in the right direction.

I was looking at the NSSlider doc's, and not at the NSSliderCell doc's.


Regards Mark