SwiftUI GroupBox

황인성·2025년 2월 17일

iOS

목록 보기
10/24
post-thumbnail

  • 타이틀 + 콘텐츠를 포함할 수 있음
  • label을 사용해 제목을 설정할 수 있음.
  • 내부에서 VStack, HStack, Form 등을 사용할 수 있음.
  • 설정 화면에서 관련된 옵션을 묶을 때 유용함.
  • 그룹박스의 배경이 되는 둥근 사각형은 바꿀 수 없다
  • font를 바꿔도 label의 폰트는 바뀌지 않는다
struct GroupBox: View {
    @State private var notificationsEnabled = true
        
        var body: some View {
            Form {
                GroupBox(label: Text("알림 설정")) {
                    Toggle("푸시 알림 받기", isOn: $notificationsEnabled)
                }
                
                GroupBox(label: Text("계정 정보")) {
                    VStack(alignment: .leading) {
                        Text("이름: 홍길동")
                        Text("이메일: hong@example.com")
                    }
                    .padding(.top, 5)
                }
            }
            .navigationTitle("설정")
        }
}
profile
iOS, Spring developer

0개의 댓글