Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI - How to resize PickerView?

Tags:

swiftui

picker

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

     }
   }
}
like image 589
Luke Ireton Avatar asked Feb 05 '20 15:02

Luke Ireton


1 Answers

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

like image 118
user3441734 Avatar answered Jan 23 '23 13:01

user3441734