Вы можете использовать отдельные Section
s для создания верхних колонтитулов (и, необязательно, нижних колонтитулов).
import SwiftUI
struct Node : Identifiable {
let id = UUID()
let name: String
let children: [Node]?
}
struct SectionedOutlineView: View {
var body: some View {
List(selection: $selection) {
Section(header: Label("Nodes 1", systemImage: "sparkle")) {
OutlineGroup(nodes1, children: \.children) { node in
Label(node.name, systemImage: "shield")
}
}
Section(header: Label("Nodes 2", systemImage: "rosette")) {
OutlineGroup(nodes2, children: \.children) { node in
Label(node.name, systemImage: "folder")
}
}
}
.listStyle(SidebarListStyle())
}
@State var nodes1 = [
Node(name: "Layer 1", children: [
Node(name: "Layer 1-1", children: [
Node(name: "Layer 1-1-1", children: nil),
Node(name: "Layer 1-1-2", children: nil),
]),
Node(name: "Layer 1-2", children: [
Node(name: "Layer 1-2-1", children: nil),
Node(name: "Layer 1-2-2", children: nil),
Node(name: "Layer 1-2-3", children: nil),
]),
Node(name: "Layer 1-3", children: nil),
]),
Node(name: "Layer 2", children: [
Node(name: "Layer 2-1", children: [
]),
Node(name: "Layer 2-2", children: [
]),
Node(name: "Layer 2-3", children: [
]),
])
]
@State var nodes2 = [
Node(name: "Layer 1", children: [
Node(name: "Layer 1-1", children: [
Node(name: "Layer 1-1-1", children: nil),
Node(name: "Layer 1-1-2", children: nil),
]),
Node(name: "Layer 1-2", children: [
Node(name: "Layer 1-2-1", children: nil),
Node(name: "Layer 1-2-2", children: nil),
Node(name: "Layer 1-2-3", children: nil),
]),
Node(name: "Layer 1-3", children: [
]),
]),
Node(name: "Layer 2", children: [
Node(name: "Layer 2-1", children: [
]),
Node(name: "Layer 2-2", children: [
Node(name: "Layer 2-2-1", children: nil),
Node(name: "Layer 2-2-2", children: nil),
Node(name: "Layer 2-2-3", children: nil),
]),
Node(name: "Layer 2-3", children: [
]),
])
]
@State var selection = Set<Node.ID>()
}