\n","author":{"@type":"Person","name":"leonboe1"},"upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"
The width: 10
is too small... anyway, use .clipped (or .clipShape) to restrict drawing outside bounds
Picker(selection: self.$position, label: Text("")){\n ForEach(0..<50){ i in\n Text("\\(i)")\n }\n}\n.frame(width: 50, height: 150, alignment: .center)\n.clipped() // << here !!\n
\n","author":{"@type":"Person","name":"Asperi"},"upvoteCount":1}}}Reputation: 1185
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()
}
}
}
Upvotes: 1
Views: 1770
Reputation: 258541
The width: 10
is too small... anyway, use .clipped (or .clipShape) to restrict drawing outside bounds
Picker(selection: self.$position, label: Text("")){
ForEach(0..<50){ i in
Text("\(i)")
}
}
.frame(width: 50, height: 150, alignment: .center)
.clipped() // << here !!
Upvotes: 1