使用区别:OutlineGroup使用前需要构造好数据模型
1. DisclosureGroup
结合List使用
List{
DisclosureGroup("点击展开",isExpanded: $isExpanded){
Text("子菜单")
DisclosureGroup("第二级:点击展开"){
Text("子菜单")
Text("子菜单")
Text("子菜单")
}
}
DisclosureGroup("点击展开"){
Text("子菜单")
Toggle("toggle", isOn: $toggleIsOn)
DisclosureGroup("第二级:点击展开"){
Text("子菜单")
Text("子菜单")
Text("子菜单")
}
}
}
结合Form使用
Form{
DisclosureGroup("点击展开"){
Text("子菜单")
Toggle("toggle", isOn: $toggleIsOn)
DisclosureGroup("第二级:点击展开"){
Text("子菜单")
Text("子菜单")
Text("子菜单")
}
}
}
2. OutlineGroup
import SwiftUI
struct User:Identifiable {
let id = UUID()
var name = ""
var users:[User]? = nil
}
struct ContentView: View {
let user = User(
name: "同学",users: [
User(name: "cy",users: [
User(name: "CY_SUB1"),
User(name: "CY_SUB2")
]
),
User(name: "cy1")
]
)
var body: some View {
Form{
OutlineGroup(user, children: \.users) { user in
Text(user.name)
}.padding(10)
}
}
}
网友评论