[SwiftUI] Basic usage of GroupBox

code:

import SwiftUI

struct MPMineView: View {
    
    @State var selectType: Int = 10
    @State var vpnIsOn: Bool = false
    
    var body: some View {
        VStack {
            GroupBox(label: Label("分组一", systemImage: "rectangle.3.group.fill")) {
                HStack {
                    Text("WiFi")
                        .frame(maxWidth: .infinity, alignment: .leading)
                    Picker("WiFi选择", selection: $selectType) {
                        Text("one").tag(10)
                        Text("two").tag(11)
                        Text("three").tag(12)
                    }
                }
                HStack {
                    Label("蓝牙", systemImage: "lasso")
                        .frame(maxWidth: .infinity, alignment: .leading)
                    Text("未连接")
                    Image(systemName: "chevron.right")
                }
                Toggle(isOn: $vpnIsOn) {
                    Label("VPN", systemImage: "wifi.circle")
                }
                Button {
                    print("\(selectType)")
                } label: {
                    Text("打印WiFi选择结果")
                }
            }
            .padding(EdgeInsets(top: 0, leading: 15, bottom: 0, trailing: 15))
            
            GroupBox(label: Label("分组二", systemImage: "rectangle.3.group.fill")) {
                Label("通知", systemImage: "bolt.fill")
                    .frame(maxWidth: .infinity, minHeight: 36, alignment: .leading)
                Label("专注模式", systemImage: "bolt.fill")
                    .frame(maxWidth: .infinity, minHeight: 36, alignment: .leading)
                    .labelStyle(.titleOnly)
                Label("屏幕使用时间", systemImage: "bolt.fill")
                    .frame(maxWidth: .infinity, minHeight: 36, alignment: .leading)
                    .labelStyle(.iconOnly)
            }
            .padding(EdgeInsets(top: 0, leading: 15, bottom: 0, trailing: 15))
        }
    }
}

hint:

 

Guess you like

Origin blog.csdn.net/u012881779/article/details/129721403