macOS 的检查器面板

一个 Cocoa 自动布局管理的视图,用于构建和管理与 Apple Pages 和 Numbers 应用程序中的检查器等效的检查器面板。

为什么需要它?

我在许多不同的项目中实现并与之斗争过,所以我决定创建一个即插即用的类,它可以完成我想要的一切。这个类完全由自动布局管理。

我非常喜欢 Apple 的 'Pages' 实现,它允许有一个标题视图,即使在面板本身隐藏时也可以用于配置项目。一个很好的例子是“间距”检查器面板,当面板隐藏时,用户仍然可以以更小的粒度更改行距。

已展开 已收缩

特性

安装

直接安装

DSFInspectorPanes 子文件夹中的 swift 文件复制到您的项目

CocoaPods

将以下内容添加到您的 Podfiles 文件中

pod 'DSFInspectorPanes', :git => 'https://github.com/dagronf/DSFInspectorPanes'

API

创建

  1. 创建一个 DSFInspectorPanesView 的实例并将其添加到视图中,或者
  2. 使用 Interface Builder 添加一个自定义视图,并将类更改为 DSFInspectorPanesView

属性

方法

添加一个检查器面板

向容器添加一个新的检查器面板

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()

鸣谢

RSVerticallyCenteredTextFieldCell - Red Sweater Software

DraggableStackView - Mark Onyschuk

屏幕截图

(视频) 拖放重新排序

Interface Builder 集成

面板模式

演示了当面板收缩时显示辅助 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.