Gurmukh Singh
Gurmukh Singh

Reputation: 2017

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())

Upvotes: 2

Views: 5306

Answers (1)

Asperi
Asperi

Reputation: 258365

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))
    }

}

Upvotes: 2

Related Questions