Picker

2020-03-30  本文已影响0人  水之飞亦

Creating a Picker

init(LocalizedStringKey, selection: Binding<SelectionValue>, content: () -> Content)

Available when Label is Text.

init<S>(S, selection: Binding<SelectionValue>, content: () -> Content)

Available when Label is Text.

init(selection: Binding<SelectionValue>, label: Label, content: () -> Content)

Creates an instance that selects from content associated with Selection values.

Styling Pickers

struct DefaultPickerStyle
struct PopUpButtonPickerStyle
struct RadioGroupPickerStyle
struct SegmentedPickerStyle
struct WheelPickerStyle

protocol PickerStyle

A custom specification for the appearance and interaction of a Picker.

var section = ["1","2","3","4","5","6"]
@State var selectRow = 1
var body: some View {
    
    VStack {
        
        Picker.init("Picker", selection: $selectRow) {
            ForEach(0..<self.section.count) { i in
                Text(self.section[i])
            }
        }
        
        .pickerStyle(SegmentedPickerStyle())
        
        Picker.init(selection: $selectRow, label: Text("Picker")) {
            ForEach(0..<self.section.count) { i in
                Text(self.section[i])
            }
        }
        .pickerStyle(WheelPickerStyle())
        .foregroundColor(Color.purple)
        .background(Color.init(red: 0.9, green: 0.9, blue: 0.9))
        .font(Font.system(size: 20))
        
        
    }.padding(EdgeInsets(top: 20, leading: 20, bottom: 20, trailing: 20))
    
}
上一篇下一篇

猜你喜欢

热点阅读