Luke Ireton
Luke Ireton

Reputation: 509

SwiftUI - How to resize PickerView?

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

     }
   }
}

Upvotes: 13

Views: 20999

Answers (1)

user3441734
user3441734

Reputation: 17572

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

Upvotes: 38

Related Questions