Skip to content

Instantly share code, notes, and snippets.

@usagimaru
Last active March 5, 2024 19:15
Show Gist options
  • Save usagimaru/4be48bf1ff5451bfa525a021f937b485 to your computer and use it in GitHub Desktop.
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)
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
}
}
}
@usagimaru
Copy link
Author

usagimaru commented Mar 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment