2
votes

I've used Storyboard to set up the NSScrollView and I cannot find any option where I can disable the scroller's background. Any ideas on how to make this happen?

NSScroller Background Color

3
Subclass NSScroller.El Tomato
Yes, I've Subclass NSScroller but AutoHideScroller does not work...dbrownjave
What version of macOS are you targeting?Jake3231
version 10.13.5dbrownjave

3 Answers

3
votes

Basically idea behind this is subclass the NSScroller and then make changes accordingly.

I had the same requirement so I subclassed it and did the changes as shown. objective c code is converted with help of online tool so apologies for mistakes and have look.

this may help.

//  Converted to Swift 4 by Swiftify v4.1.6766 - https://objectivec2swift.com/
//  GridScroller.h
//  Created by Vikram on 08/09/16.

import Cocoa

class OpaqGridScroller: NSScroller {
    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect)
        NSColor.clear.setFill()
        dirtyRect.fill()
        // whatever style you want here for knob if you want
        knobStyle = .dark
    }
}
1
votes

You can try override draw scroller rect

override func draw(_ dirtyRect: NSRect) {
    NSDrawWindowBackground(bounds);
    self.drawKnob()
}

You always can draw custom rect color by setting it before

override func draw(_ dirtyRect: NSRect) {
    NSColor.clear.set()
    __NSRectFill(dirtyRect)

    self.drawKnob()
}
1
votes

This solution worked for me.

class OpaqueGridScroller: NSScroller {
    override func draw(_ dirtyRect: NSRect) {
        // NSColor.clear.set()
        // dirtyRect.fill()
        self.drawKnob()
    }
}