简体   繁体   English

不扩展NSScroller

[英]Not expanding NSScroller

The NSScroller automatically expands it's width when the user hovers over it. 当用户将鼠标悬停在其上时, NSScroller自动扩展其宽度。

在此处输入图片说明

However, the document view has pretty little space, and this is why the scroller should not expand. 但是,文档视图的空间很小,这就是滚动条不应展开的原因。

How can I disable this behaviour? 如何禁用此行为?

This maybe a little too late, but something like this might help? 这也许为时已晚,但是这样可能有所帮助?

1) Create custom scroller for your vertical scrollbar. 1)为您的垂直滚动条创建自定义滚动条。

2) Override - drawKnob to force draw knob the default size even when it is to be drawn 'expanded'. 2)覆盖-drawKnob强制“绘制”旋钮达到默认大小,即使要“展开”也是如此。

-(void)drawKnob
{
    NSRect knobSlot = [self rectForPart:NSScrollerKnob];
    if(sFlags.isHoriz)
    {
        knobSlot.size.height = 9;
        knobSlot.origin.y = 6;
    }
    else
    {
        knobSlot.size.width  = 9;
        knobSlot.origin.x = 6;
    }

    NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:knobSlot xRadius:5 yRadius:5];

    [[NSColor scrollBarColor] set];
    [path fill];
}

3) Depending on if you still want the knob slot or not, override - drawKnobSlotInRect : 3)根据是否仍然需要旋钮插槽,重写-drawKnobSlotInRect

-(void)drawKnobSlotInRect:(NSRect)slotRect highlight:(BOOL)flag
{
    NSRect newRect = slotRect;
    if(sFlags.isHoriz)
        newRect.origin.y = 4;
    else
        newRect.origin.x = 4;
    [super drawKnobSlotInRect:newRect highlight:flag];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM