Xcode 8.2.1, Swift 3.0.2, macOS 10.12
I have an NSSplitViewController
that has 3 panes (please note the NS
; this is for a Mac app).
I'm trying to set the left-most pane to always have a fixed width and not be resizable. I have tried the following:
constrainMaxCoordinate
and constrainMinCoordinate
didn't work.Has anyone else gotten this to work lately? There are lots of articles about this topic, but their toolsets are several years old and none of their suggestions have worked for me. Thanks!
I finally figured this out. I had to set an auto layout constraint programmatically. Setting a constraint on an NSSplitViewItem
was not available in the storyboard editor (Xcode 8.1).
Here's how I did it:
//This is my SplitViewController subclass
class MainSplitVC: NSSplitViewController {
//Outlet to the menu pane
@IBOutlet weak var menuPane: NSSplitViewItem!
override func viewDidLoad() {
super.viewDidLoad()
//Hard-code the width of the menu pane
NSLayoutConstraint(item: menuPane.viewController.view, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 80).isActive = true
}
}
I hope that helps someone else.
Usually you should set a layout constraints to subviews of the child view.
For example, if you have an NSOutlineView in the left pane, just set it's width constraint to a fixed value.
The size of a pane's view is calculated by the constraints of it's subviews.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With