Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change height of a Picker with SegmentedPickerStyle() in SwiftUI?

Tags:

ios

swift

swiftui

How do I change the Picker Frame in SwiftUI?

Picker(selection: .constant(1), label: Text("Picker")) {
    Text("Hello").tag(1)
    Text("World").tag(2)
}
.frame(height: 60)
.pickerStyle(SegmentedPickerStyle())

We expect the picker height to equal 60, but it doesn't.

like image 648
Fish Balloon Avatar asked Oct 29 '19 14:10

Fish Balloon


1 Answers

There is no direct way to change the height of the SegmentedPickerStyle picker but we can scale it using the following code.

Picker(selection: .constant(1), label: Text("Picker")) {
    Text("Hello").tag(1)
    Text("World").tag(2)
}
.frame(height: 60)
.pickerStyle(SegmentedPickerStyle())
.scaledToFit()
.scaleEffect(CGSize(width: 1.5, height: 1.5))
like image 76
Nilay Avatar answered Nov 05 '22 02:11

Nilay