4

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

Blaszard
  • 30,954
  • 51
  • 153
  • 233

1 Answers1

11

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()
    }

}
Paul Patterson
  • 6,840
  • 3
  • 42
  • 56
  • That might be able to be simplified into just `override var dividerColor: NSColor{ return NSColor.redColor() }`, because the `get` is implied. – erdekhayser Jan 26 '15 at 04:25
  • Thanks - didn't realise the ``get`` could be dropped. Have edited accordingly. – Paul Patterson Jan 26 '15 at 13:42
  • Thanks. Still not sure whether this passes Apple's review, but I would try. – Blaszard Jan 26 '15 at 23:15
  • If by *review* you mean the process Apple puts an app through before clearing it for the App Store, I'd be surprised if they would fail you simply for changing the divider color of a split-view. After all, they've provided explicit API to allow you to do it! – Paul Patterson Jan 26 '15 at 23:23