A Cocoa, auto-layout managed view to build and manage inspector panes equivalent to the inspectors in Apple's Pages and Numbers applications.
I've implemented and fought with this on a number of different projects and decided to make a drop-in class that would do everything that I wanted. This class is fully autolayout managed.
I really like Apple 'Pages' implementation which allows having a header view which can be used to configure items even when the pane itself is hidden. A good example of this is the 'Spacing' inspector pane, where when the pane is hidden the user can still change the line spacing at a lower granularity.
Expanded | Contracted |
---|---|
- Show and hide panes
- Configurable from interface builder as inspectables
- Optional supply a view as a header view, and set its visibility (always show, show when collapsed)
- Optional automatic scroll view support
- Optional animation
- Optional separators or bounding boxes
- Optional drag/drop reordering of panes
- Show or hide individual panes without removing them
- Expand or contract individual panes
Copy the swift files from the DSFInspectorPanes
subfolder to your project
Add the following to your Podfiles
file
pod 'DSFInspectorPanes', :git => 'https://github.com/dagronf/DSFInspectorPanes'
- Create an instance of
DSFInspectorPanesView
and add it to a view, or - Use Interface Builder to add a custom view, and change the class to
DSFInspectorPanesView
animated
: Animate the expanding/hiding of the panesembeddedInScrollView
: Embed the panes view in a scroll viewshowSeparators
: Insert a separator between each pane (optional)showBoxes
: Show a box around each inspector pane (optional)titleFont
: Specify a custom font to use for the title for the panesspacing
: Set the vertical spacing between each panecanDragRearrange
: Allow the user to change the ordering of the panes via drag/drop or touchbar
Add a new inspector pane to the container
var propertyPanes = DSFInspectorPanesView(
frame: .zero,
animated: true,
embeddedInScrollView: false,
titleFont: NSFont.systemFont(ofSize: 13)
)
var inspectorView = NSView() // <--- your inspector pane view
var inspectorHeaderView = NSView() // <--- your inspector pane header view
propertyPanes.addPane(
title: "My inspector Pane",
view: inspectorView,
headerAccessoryView: inspectorHeaderView,
expansionType: .expanded)
}
var propertyPanes = DSFInspectorPanesView()
…
propertyPanes.panes[0].expanded = true
propertyPanes.panes[1].expanded = false
var propertyPanes = DSFInspectorPanesView()
…
propertyPanes.panes[0].isHidden = true
propertyPanes.panes[1].isHidden = false
Move the property pane at index 0 to index 4
propertyPanes.move(index: 0, to: 4)
Swap property panes at index 0 and index 4
propertyPanes.swap(index: 0, with: 4)
Remove the pane at index 1
propertyPanes.remove(at: 1)
Remove all panes
propertyPanes.removeAll()
- Red Sweater Software, LLC for RSVerticallyCenteredTextFieldCell component — License
- Mark Onyschuk on GitHub -- Draggable Stack View
Showing the ability to display a secondary UI element for when the pane is contracted
MIT License
Copyright (c) 2024 Darren Ford
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.