SwiftUI DisclosureGroup

황인성·2025년 2월 16일

iOS

목록 보기
8/24
post-thumbnail

  • DisclosureGroup으로 아래로 뷰를 접었다 펼쳤다 하기 가능
  • DisclosureGroup안에 DisclosureGroup 중첩 가능
  • DisclosureGroup을 List에 넣으면 정상작동 안 할수도 있다. ForEach에 넣으면 해결됨
  • DisclosureGroup은 좌우는 최대로 커지고, 상하는 최소로 작아짐
  • DisclosureGroup을 content와 label로 작성할때 label에는 HStack이 기본으로 들어가 있다
struct DisclosureGroup: View {
    var body: some View {
        VStack {
            Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
            DisclosureGroup("Group") {
                DisclosureGroup("Group") {
                    DisclosureGroup("Group") {
                        RoundedRectangle(cornerRadius: 25.0)
                            .frame(height: 200)
                    }
                    .padding()
                    .background(Color.pink.opacity(0.7))
                }
                .padding()
                .background(Color.pink.opacity(0.7))
            }
            .padding()
            .background(Color.pink.opacity(0.7))
            
            ScrollView {
                ForEach(0 ..< 50) { item in
                    DisclosureGroup(
                        content: {
                            RoundedRectangle(cornerRadius: 25.0)
                                .frame(height: 200)
                        },
                        label: {
                            Image(systemName: "moon.fill")
                            Text("Moon Cycle")
                        })
                        .padding()
                }
            }
        }
    }
}

DisclosureGroup

profile
iOS, Spring developer

0개의 댓글