简体   繁体   English

如何在自定义NSView中使用NSScroller

[英]How to use NSScroller in a custom NSView

I have a custom NSView with two NSClipViews. 我有一个带有两个NSClipViews的自定义NSView。 I want to add a vertical scroller for each clipview. 我想为每个剪辑视图添加一个垂直滚动条。 The snippet below shows a NSScroller, but it is not drawing any knob or buttons. 下面的代码段显示了一个NSScroller,但它没有绘制任何旋钮或按钮。 Interaction is also not possible. 互动也是不可能的。 NSScroller is a small class, so I am not sure what I am missing here. NSScroller是一个小班,所以我不确定我在这里缺少什么。

required init?(coder: NSCoder)
{
    super.init(coder: coder)

    let width = NSScroller.scrollerWidthForControlSize(NSControlSize.RegularControlSize, scrollerStyle: NSScrollerStyle.Overlay)

    let scroller = NSScroller(frame: NSRect(x: 10, y: 10, width: width, height: 500))
    self.addSubview(scroller)
    scroller.doubleValue = 0.5
    scroller.knobProportion = 0.1
    scroller.needsLayout = true  //no effect
    scroller.needsDisplay = true //no effect
}

缺失的一行:

scroller.enabled = true

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

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