Swift Pickerのスタイルを設定するサンプル
環境
Swift version 5.2.3 (swift-5.2.3-RELEASE)
Ubuntu 20.04.2 LTS
構文
Picker(xxx)
.pickerStyle(PickerStyle())
Picker(xxx)
.pickerStyle(PickerStyle())
Picker(xxx) .pickerStyle(PickerStyle())
pickerStyle修飾子にPickerStyleのインスタンスを指定することで、
Pickerの表示スタイルを設定します。
使用例
struct ContentView: View {
@State private var selectedIndex = 0
var body: some View {
VStack {
Picker(selection: $selectedIndex, label: Text("")) {
//処理コード
}
.pickerStyle(SegmentedPickerStyle())
}
}
struct ContentView: View {
@State private var selectedIndex = 0
var body: some View {
VStack {
Picker(selection: $selectedIndex, label: Text("")) {
//処理コード
}
.pickerStyle(SegmentedPickerStyle())
}
}
struct ContentView: View { @State private var selectedIndex = 0 var body: some View { VStack { Picker(selection: $selectedIndex, label: Text("")) { //処理コード } .pickerStyle(SegmentedPickerStyle()) } }