我正在用自定義NSSliderCell創建自定義NSSlider。除了旋鈕之外,所有工作都非常漂亮。當我將其拖動到最大值時,旋鈕被剪切,我只能看到50%的旋鈕圖像。NSSlider NSSliderCell剪裁自定義旋鈕
當分配我的自定義NSSliderCell時,我將knobThickness設置爲我用作旋鈕的圖像的寬度。我認爲(我猜錯了)它會考慮到這一點,並阻止它從剪輯?
任何想法我做錯了什麼?僅當旋鈕被裁剪爲50%時,滑塊纔會擊中maxValue,所以它不會在沒有添加任何值的情況下移動。
- (void)drawKnob:(NSRect)knobRect {
NSImage * knob = _knobOff;
knobRectVar = knobRect;
[[self controlView] lockFocus];
[knob
compositeToPoint:
NSMakePoint(knobRect.origin.x+4,knobRect.origin.y+knobRect.size.height+20)
operation:NSCompositeSourceOver];
[[self controlView] unlockFocus];
}
- (void)drawBarInside:(NSRect)rect flipped:(BOOL)flipped {
rect.size.height = 8;
[[self controlView] lockFocus];
NSImage *leftCurve = [NSImage imageNamed:@"customSliderLeft"];
[leftCurve drawInRect:NSMakeRect(5, 25, 8, 8) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1];
NSRect leftRect = rect;
leftRect.origin.x=13;
leftRect.origin.y=25;
leftRect.size.width = knobRectVar.origin.x + (knobRectVar.size.width/2);
[leftBarImage setSize:leftRect.size];
[leftBarImage drawInRect:leftRect fromRect: NSZeroRect operation: NSCompositeSourceOver fraction:1];
[[self controlView] unlockFocus];
}
它吸引50%的旋鈕被削去,並且沒有+20.0 – mootymoots 2011-01-26 19:34:30