Mac NSSlider customizing ?

Mark FX

macrumors regular
Original poster
Nov 18, 2011
121
10
West Sussex, UK
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

macrumors regular
Apr 8, 2009
115
0
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.
 
Comment

Mark FX

macrumors regular
Original poster
Nov 18, 2011
121
10
West Sussex, UK
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
 
Comment

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
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.
 
Comment

Mark FX

macrumors regular
Original poster
Nov 18, 2011
121
10
West Sussex, UK
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
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.