Search code examples
swiftswiftuiuipickerview

SwiftUI - Styling Picker


I have a Picker like this:

enter image description here

Im trying to change the style so it pops up like the keyboard does, see example:

enter image description here

This is my code at the moment:

Picker(selection: $profileViewModel.age, label: Text("Age")) {
     ForEach(0 ..< 100) { number in
          Text("\(number)")
     }
}.pickerStyle(WheelPickerStyle())

Solution

  • Here is a demo of some approach... tested with Xcode 12 / iOS 14

    demo

    var body: some View {
        VStack(spacing: 0) {
            Spacer()
            Divider()
            Picker(selection: $age, label: Text("Age")) {
                 ForEach(0 ..< 100) { number in
                      Text("\(number)")
                 }
            }.pickerStyle(WheelPickerStyle())
            .frame(maxWidth: .infinity)
            .background(Color(UIColor.systemGroupedBackground).edgesIgnoringSafeArea(.bottom))
        }
    
    }