1

我想使用 NSSlider 来控制分机。设备。因为分机。设备很慢,滑块应在其旋钮内显示 NSProgressIndicator,直到设备达到滑块指定的值。但是没有显示条形图和微调器(旋钮保持默认外观)。有什么建议么?

@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 setStyle:NSProgressIndicatorSpinningStyle];
        [spinner startAnimation:self];
    }
    return self;
}
@end

编辑:这个版本最终显示旋钮内的微调器。但是当滑块移动时,微调器停止动画。我要放弃...

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

0 回答 0