[SwiftUI]Form的基本使用

代码:

import SwiftUI

struct MPMineView: View {
    
    enum SectionOneType {
        case one
        case two
        case three
    }
    @State var selectOneType = SectionOneType.one
    @State var statusOne = false
    @State var statusTwo = true
     
    enum SectionTwoType: Int {
        case one = 1000
        case two = 1001
        case three = 1002
    }
    @State var selectTwoType = SectionTwoType.two
    
    enum SectionThreeType: String {
        case one
        case two = "two"
        case three
    }
    @State var selectThreeType = SectionThreeType.three
    
    var body: some View {
        NavigationView {
            Form {
                Section(header: Text("第一部分")) {
                    Picker("选择数字", selection: $selectOneType) {
                        Text("一").tag(SectionOneType.one)
                        Text("二").tag(SectionOneType.two)
                        Text("三").tag(SectionOneType.three)
                    }
                    Toggle("状态一", isOn: $statusOne)
                    Toggle("状态二", isOn: $statusTwo)
                    HStack {
                        Label("版本号", systemImage: "square.and.arrow.up.on.square").frame(maxWidth: .infinity, alignment: .leading)
                        Text("居中")
                        Text("1.0.0").frame(maxWidth: .infinity, alignment: .trailing)
                    }
                }
                Section(header: Text("第二部分")) {
                     Picker("选择数字", selection: $selectTwoType) {
                         Text("一").tag(SectionTwoType.one)
                         Text("二").tag(SectionTwoType.two)
                         Text("三").tag(SectionTwoType.three)
                     }.pickerStyle(.inline)
                }
                Section(header: Text("第三部分")) {
                    Picker("选择数字", selection: $selectThreeType) {
                         Text("一").tag(SectionThreeType.one)
                         Text("二").tag(SectionThreeType.two)
                         Text("三").tag(SectionThreeType.three)
                    }.onReceive([self.selectThreeType].publisher.first()) { value in
                        // 选项改变时 回调
                        print("value = \(value)")
                    }
                     Button("清理缓存") {}
                }
            }
        }
    }
}
                   

struct MPMineView_Previews: PreviewProvider {
    static var previews: some View {
        MPMineView()
    }
}

示意:

猜你喜欢

转载自blog.csdn.net/u012881779/article/details/129708801