「SwiftUI」常用的Picker

Posted by Jiaolong on 2022/04/02

Base

struct PickerView: View {
    @State private var selected = 0

    var body: some View {
        Picker("Flavor", selection: $selected) {
            Text("Chocolate 🍫")
                .tag(0)
            Text("Vanilla 🍦")
                .tag(1)
            Text("Strawberry 🍓")
                .tag(2)
        }
        Text("Selected : \(selected)")
    }
}

image-20220402131006527

Style

默认

image-20220403192353823

SegmentedPickerStyle

.pickerStyle(SegmentedPickerStyle())

image-20220403192629935