Why not create directly an NSScrollView ?
It is advised in Apple's doc:
Typically, you don’t need to program with scrollers; instead, you configure them with an
If you still need to create programmatically, could you show how you created the scroll bars ?
I have create a short demo code without problem, just setting the frame rectangle.
@IBOutlet weak var viewWithScrollers: NSView! let hScroll = NSScroller(frame: NSRect(x: 0, y: 0, width: 160, height: 12)) hScroll.scrollerStyle = .legacy let vScroll = NSScroller(frame: NSRect(x: viewWithScrollers.frame.width - 12, y: 0, width: 12, height: 100)) vScroll.scrollerStyle = .overlay viewWithScrollers.addSubview(vScroll) viewWithScrollers.addSubview(hScroll)
Thanks, your example helped me to figure it out.
The type of scroll-bar (horizontal or vertical) is determined by it's frame size when it is created.
I've created my scroll-bars in my custom view's init() with the frame set to .zero (since my view does not have a size yet). The frame was adjusted when the view got layed out but at that time it is too late and it does not change.
The fix was to use an arbitary frame size that is wider than it is taller in order to get a horizontal scroll bar, and taller than wider to get a vertical one.