article

Saturday, August 7, 2021

SwiftUI GroupBox Example

SwiftUI GroupBox Example

SwiftUI Group Boxes can be used to combine related views.
ContentView.swift
//
//  ContentView.swift
//  swiftuidev
//
//  Created by Cairocoders
//

import SwiftUI

struct ContentView: View {
    @State private var name = ""
    
    var body: some View {
        VStack {

            GroupBox(label: Label("Heart rate", systemImage: "heart.fill").font(.largeTitle).foregroundColor(.red)) {
                Text("69 BPM").font(.title)
            }

            GroupBox {
                Text("Enter your name").font(.title)
                TextField("name", text: $name)
            }
            Spacer()
        }.padding(.horizontal)
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Related Post