开发者

show a spinner inside NSSlider's knob

I'd like to use NSSlider to control an ext. device. Because the ext. device is slow the slider shall display NSProgressIndicator WITHIN IT'S KNOB until the device achieves the value specified by the slider. But neither the bar nor the spinner are shown (the knob keeps it's default look). Any suggestions?

@implementation SubclassedNSSliderCell

-(void)drawKnob:(NSRect)knobRect
{
    [spinner setFrame:knobRect]; // as suggested by jtbandes
    [super drawKnob:knobRect]; // keep the default knob
    [spinner drawRect:knobRect]; // draw the spinner on top
}
-(void)drawBarInside:(NSRect)frame flipped:(BOOL)flipped
{
    // stick with default bar
    [super drawBarInside:frame flipped:flipped];
}
-(BOOL)_usesCustomTrackImage
{
    return YES;
}

// default stuff here...
-(id)init // nothing interesting here...
{
    if ((self = [super init]))
    {
        spinner = [[NSProgressIndicator alloc] initWithFrame:
            NSMakeRect(0.f, 0.f, 20.f, 20.f)];
        [spinner se开发者_Go百科tStyle:NSProgressIndicatorSpinningStyle];
        [spinner startAnimation:self];
    }
    return self;
}
@end

EDIT: This version finally displays the spinner inside the knob. But the spinner stops animating when the slider is moved. I'm giving up...

-(void)drawKnob:(NSRect)knobRect
{
    [super drawKnob:knobRect];
    [[self controlView] addSubview:spinner];
    [spinner setFrame:knobRect];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜