Home > AI > IOS > SwiftUI >

show multiple picker view in HStack

struct ContentView: View {
    @State var s1: Int = 1
    @State var s2: Int = 1
    @State var s3: Int = 1
        
    var body: some View{
 
        HStack(spacing: 0) {
            PickerUnitView(selection: $s1)
            PickerUnitView(selection: $s2)
            PickerUnitView(selection: $s3)
        }
    }
}


struct PickerUnitView: View {
    @Binding var selection: Int
    
    var body: some View {
        Picker("good", selection: $selection) {
            Text("1")
                .tag(1)
            Text("2")
                .tag(2)
        }
        .frame(width: 50)
        .clipped()
    }
}

Leave a Reply