Customize knob image of NSScroller

  • I am trying to customize the knob's image of my horizontal NSScroller.
    I would like to do something similar to iTunes. It seems that the image I
    have to use is just one

        [knobCell setImage:[NSImage imageNamed:@"icn_knob"]];

    so I thought to set an image of a circle and that Cocoa should have split
    that in 3 images:
        a) the half a circle at the left side
        b) a vertical line to be stretched horizontally in the middle
        c) the half a circle at the right side.

    So I did set an image of a circle, but I have seen that it gets stretched
    along the width of the knob. Too bad.
    Then I tried to set a 1 x 15 vertical line image, and I got a 1 x 15 line
    over a gray rectangle. Too bad. I overrode these methods

    - (void)drawParts
        if (knobCell) return;
        knobCell = [NSButtonCell new];
        [knobCell setButtonType:NSMomentaryChangeButton];
        [knobCell setImage:[NSImage imageNamed: @"icn_scroll_knob_m"]];
        [knobCell setImagePosition:NSImageOnly];

    - (void)drawKnob
        NSRect rect = [self rectForPart: NSScrollerKnobSlot];
        [[NSColor scrollBarColor] set];

        rect = [self rectForPart:NSScrollerKnob];
        [knobCell drawWithFrame:rect inView:self];


    What did I forget?

    Best Regards
    email: <archidea...>
previous month november 2007 next month
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today