Last active
March 16, 2026 04:12
-
-
Save usagimaru/4be48bf1ff5451bfa525a021f937b485 to your computer and use it in GitHub Desktop.
Get NSSplitView’s divider view from a subclass (customize divider height and color)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Cocoa | |
| class SplitView: NSSplitView { | |
| override var dividerThickness: CGFloat { | |
| 50 | |
| } | |
| override var dividerColor: NSColor { | |
| NSColor.red | |
| } | |
| private func searchDividerView() -> [NSView] { | |
| let dividers = subviews.compactMap { | |
| type(of: $0) == NSClassFromString("NSSplitDividerView") ? $0 : nil | |
| }.sorted { v1, v2 in | |
| if self.isVertical { | |
| return v1.frame.minY > v2.frame.minY | |
| } | |
| return v1.frame.minX < v2.frame.minX | |
| } | |
| return dividers | |
| } | |
| override func awakeFromNib() { | |
| super.awakeFromNib() | |
| if let dividerView = searchDividerView().first { | |
| // do something | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Postscript:
I think the method to customize the rect of the divider using the Delegate looks better.
Hiding Dividers in NSSplitView
https://stackoverflow.com/questions/60165351/hiding-dividers-in-nssplitview