GroupBox

A stylized view, with an optional label, that visually collects a logical grouping of content.

ComponentiOS 14.0+macOS 10.15+GroupBox in SwiftUI

Declaration

React
import { GroupBox } from 'swiftui-react-native';
Swift
nonisolated struct GroupBox<Label, Content> where Label : View, Content : View

Initializers

3 SwiftUI initializers back <GroupBox>. The props you pass pick one.

React
<GroupBox>
  children?: ReactNode
</GroupBox>
Swift
nonisolated init(@ContentBuilder content: () -> Content)
  • childrenReactNode

    Content. Strings become Text; React Native views are laid out by Yoga and placed by SwiftUI.

    Swift content: () -> Content

Also takes the common view props: modifiers, style and testID.

Overview

Use a group box when you want to visually distinguish a portion of your user interface with an optional title for the boxed content.

The following example sets up a GroupBox with the label "End-User Agreement", and a long agreementText string in a SwiftUI.Text view wrapped by a SwiftUI.ScrollView. The box also contains a SwiftUI.Toggle for the user to interact with after reading the text.

var body: some View {
    GroupBox(label:
        Label("End-User Agreement", systemImage: "building.columns")
    ) {
        ScrollView(.vertical, showsIndicators: true) {
            Text(agreementText)
                .font(.footnote)
        }
        .frame(height: 100)
        Toggle(isOn: $userAgreed) {
            Text("I agree to the above terms")
        }
    }
}

From Apple’s SwiftUI documentation. Code samples there are Swift.

Relationships

Conforms to

  • View

See also

More in Views.