Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the color of NSSplitView's divider on nib?

I want to change the color of NSSplitView's dividerColor in my Cocoa app, but when I typed in the following code, the error Cannot assign to the result of this expression occurred.

splitView.dividerColor = NSColor.redColor()

I think this is because .dividerColor is a read-only property and thus you cannot overwrite the color from within code if you instantiate it from nib.

However, I cannot find any such preferences to change the color in Xcode's Inspector on the NSSplitView. So how can I change the color of the divider?

Note that I don't use NSSplitViewController; I use NSSplitView on top of the NSViewController.

enter image description here

like image 432
Blaszard Avatar asked Dec 19 '22 07:12

Blaszard


1 Answers

If you're happy to stick to using the Thin Divider style, you can change the color of the splitview's divider by using a subclass of NSSplitView, and overriding the dividerColor property:

class MySplitView: NSSplitView {

    override var dividerColor: NSColor {
        return NSColor.redColor()
    }

}
like image 56
Paul Patterson Avatar answered Jan 07 '23 05:01

Paul Patterson