Swift Pickerのスタイルを設定するサンプル

環境
Swift version 5.2.3 (swift-5.2.3-RELEASE)
Ubuntu 20.04.2 LTS

構文

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Picker(xxx)
.pickerStyle(PickerStyle())
Picker(xxx) .pickerStyle(PickerStyle())
Picker(xxx)
    .pickerStyle(PickerStyle())

pickerStyle修飾子にPickerStyleのインスタンスを指定することで、
Pickerの表示スタイルを設定します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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())
            
    }
}

 

Swift

Posted by arkgame