Structure¶
DisclosureGroup¶
A view that shows or hides another content view, based on the state of a disclosure control.¶
Declaration¶
struct DisclosureGroup<Label, Content> : View where Label : View, Content : View
Overview¶
A disclosure group view consists of a label to identify the contents, and a control to show and hide the contents. Showing the contents puts the disclosure group into the "expanded" state, and hiding them makes the disclosure group "collapsed".
In the following example, a disclosure group contains two toggles and an embedded disclosure group. The top level disclosure group exposes its expanded state with the bound property, topLevelExpanded. By expanding the disclosure group, the user can use the toggles to update the state of the toggleStates structure.
struct ToggleStates {
var oneIsOn: Bool = false
var twoIsOn: Bool = true
}
@State private var toggleStates = ToggleStates()
@State private var topExpanded: Bool = true
var body: some View {
DisclosureGroup("Items", isExpanded: $topExpanded) {
Toggle("Toggle 1", isOn: $toggleStates.oneIsOn)
Toggle("Toggle 2", isOn: $toggleStates.twoIsOn)
DisclosureGroup("Sub-items") {
Text("Sub-item 1")
}
}
}
Availability¶
iOS 14.0+
macOS 11.0+
Topics¶
Instance Property¶
body The content and behavior of the view.
Initializer¶
init(_:content:) Creates a disclosure group, using a provided string to create a text view for the label.
init(_:content:) Creates a disclosure group, using a provided localized string key to create a text view for the label.
init(_:isExpanded:content:) Creates a disclosure group, using a provided string to create a text view for the label, and a binding to the expansion state (expanded or collapsed).
init(_:isExpanded:content:) Creates a disclosure group, using a provided localized string key to create a text view for the label, and a binding to the expansion state (expanded or collapsed).
init(content:label:) Creates a disclosure group with the given label and content views.
init(isExpanded:content:label:) Creates a disclosure group with the given label and content views, and a binding to the expansion state (expanded or collapsed).
Type Alias¶
Body The type of view representing the body of this view.