leonboe1
leonboe1

Reputation: 1185

SwiftUI iOS 14 Picker width can't be changed

I can't figure out how to change the width of Picker() in SwiftUI 2, iOS 14. Is this a bug or am I missing out something? Seems like the width modifier only gets applied onto the Text but not onto the grey bar.

struct ContentView: View {
    @State private var position = 0
    var body: some View {
        VStack {
          Spacer()
            Picker(selection: self.$position, label: Text("")){
                ForEach(0..<50){ i in
                    Text("\(i)")
                }
            }
            .frame(width: 10, height: 50, alignment: .center)
            Spacer()
        }
    }
}

enter image description here

Upvotes: 1

Views: 1770

Answers (1)

Asperi
Asperi

Reputation: 258541

The width: 10 is too small... anyway, use .clipped (or .clipShape) to restrict drawing outside bounds

demo

Picker(selection: self.$position, label: Text("")){
    ForEach(0..<50){ i in
        Text("\(i)")
    }
}
.frame(width: 50, height: 150, alignment: .center)
.clipped()       // << here !!

Upvotes: 1

Related Questions