一个 Cocoa 自动布局管理的视图,用于构建和管理与 Apple Pages 和 Numbers 应用程序中的检查器等效的检查器面板。
我在许多不同的项目中实现并与之斗争过,所以我决定创建一个即插即用的类,它可以完成我想要的一切。这个类完全由自动布局管理。
我非常喜欢 Apple 的 'Pages' 实现,它允许有一个标题视图,即使在面板本身隐藏时也可以用于配置项目。一个很好的例子是“间距”检查器面板,当面板隐藏时,用户仍然可以以更小的粒度更改行距。
已展开 | 已收缩 |
---|---|
![]() |
![]() |
将 DSFInspectorPanes
子文件夹中的 swift 文件复制到您的项目
将以下内容添加到您的 Podfiles
文件中
pod 'DSFInspectorPanes', :git => 'https://github.com/dagronf/DSFInspectorPanes'
DSFInspectorPanesView
的实例并将其添加到视图中,或者DSFInspectorPanesView
animated
: 动画显示/隐藏面板embeddedInScrollView
: 将面板视图嵌入到滚动视图中showSeparators
: 在每个面板之间插入一个分隔符(可选)showBoxes
: 在每个检查器面板周围显示一个框(可选)titleFont
: 指定要用于面板标题的自定义字体spacing
: 设置每个面板之间的垂直间距canDragRearrange
: 允许用户通过拖放或触控栏更改面板的顺序向容器添加一个新的检查器面板
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
将索引 0 处的属性面板移动到索引 4 处
propertyPanes.move(index: 0, to: 4)
交换索引 0 和索引 4 处的属性面板
propertyPanes.swap(index: 0, with: 4)
移除索引 1 处的面板
propertyPanes.remove(at: 1)
移除所有面板
propertyPanes.removeAll()
演示了当面板收缩时显示辅助 UI 元素的能力
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.