NSSlider customizing ?

Discussion in 'Mac Programming' started by Mark FX, Jan 21, 2012.

  1. macrumors member

    Mark FX

    Nov 18, 2011
    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
  2. macrumors regular

    Apr 8, 2009
    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.
  3. thread starter macrumors member

    Mark FX

    Nov 18, 2011
    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
  4. macrumors 65816


    Dec 16, 2010
    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.
  5. thread starter macrumors member

    Mark FX

    Nov 18, 2011
    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

Share This Page