This article is a sample Eul chapter, if you like, please go to the AppStore/Eul to see more content.

Eul is a SwiftUI tutorial App (iOS, macOS), which is presented to readers in the form of articles (text, images, codes) and real examples (Xcode 12+, iOS 14+, macOS 11+). The author intends to explain SwiftUI related knowledge in simple and clear language as much as possible, so that readers can quickly master and practice in iOS development.

OutlineGroup

OutlineGroup is similar to the expandable List mentioned in the previous section, except that it is more widely used and we do not need to be in a List to implement the expandable function. In any View, we can use OutlineGroup for deployable functionality.

Again, take the aforementioned weathers:

OutlineGroup(expandWeather, children: \.weathers) { weather in
  Label(weather.name, systemImage: weather.icon)
}
Copy the code

This is almost exactly the same as the List used before.

DiclosureGroupView

DiclosureGroupView can also expand/close the tree structure. It is more flexible to use, and we do not have to use the data source of the tree structure to build the view. The isExpanded property of the binding makes it easy to control the display and hiding of views. The code for the example is as follows:

@State private var isExpanded = false

DisclosureGroup(isExpanded: $isExpanded, content: {
  Toggle("Unfold/fold", isOn: $isExpanded)
  DisclosureGroup("Embedded list") {
    Text("Hello 1")
    Text("Hello 1")
    Text("Hello 1")} {})Text("Disclosure")}Copy the code

As the example shows, both OutlineGroup and DiclosureGroupView can actually be nested within each other to achieve a more complex hierarchical view.

This article is a sample Eul chapter, if you like, please go to the AppStore/Eul to see more content.