0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【SwiftUI】SegmentのPicker

Last updated at Posted at 2025-06-01

アプリ開発でSegmentのPickerを実装したのでアウトプットします。

環境

macOS - Sequoia 15.4.1
Xcode - Version 16.0

コード

enum PracticeSegmentPicker: String, CaseIterable {
    case year = "年"
    case month = "月"
    case day = "日"
}

struct PracticePicker: View {
    
    @State private var segmentPicker: PracticeSegmentPicker = .year
    
    var body: some View {
        Picker("", selection: $segmentPicker) {
            ForEach(PracticeSegmentPicker.allCases, id: \.self) { picker in
                Text(picker.rawValue)
            }
        }
        .pickerStyle(SegmentedPickerStyle())
        .padding()
    }
}

これでSegmentスタイルになります。

.pickerStyle(SegmentedPickerStyle())

幅も変えることができます。

.frame(width: 200)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?