11

How do you resize the picker view in SwiftUI? I need to change the width that it takes up. My code below is just a simple view with a picker inside it. Changing the width parameter does not change the width of the picker view.

struct CalibrationBar: View {
@State var tone = Int()
var body: some View{
    HStack{

        Button(action: {
                playTone(tone: self.tone, amp: 50, stop: true)
            }) {
                Text("50 dB")
        }
        .frame(width: 60.0)

            Picker(selection: .constant(1), label: Text("")) {
            Text("+0").tag(1)
            Text("+2").tag(2)
            Text("+4").tag(3)
            }
            .clipped()
            .frame(minWidth: 0, maxWidth: 100)
            .labelsHidden()

     }
   }
}
Luke Ireton
  • 479
  • 1
  • 3
  • 18

1 Answers1

36
struct ContentView: View {
var body: some View{
    HStack{

        Button(action: {
            }) {
                Text("50 dB")
        }
        .frame(width: 60.0)

        VStack {
            Picker(selection: .constant(1), label: Text("")) {
            Text("+0").tag(1)
            Text("+2").tag(2)
            Text("+4").tag(3)
            }
            //.clipped()
            .frame(width: 50)
            .clipped()
        }.border(Color.red)
     }
   }
}

enter image description here

user3441734
  • 16,722
  • 2
  • 40
  • 59