Reputation: 20158
I have the following HStack:
HStack {
Text("Test text")
Spacer()
Picker("Test picker", selection: $selectedAccessType, content: {
Text("option1").tag(0)
Text("option2").tag(1)
})
.pickerStyle(SegmentedPickerStyle())
}
It shows up like this:
I would like to have it so the segment control's width (the Picket) is just enough wide so that the text specifying the options in each segment can fit, and not expand more than needed taking way more width than necessary. So I want its width to hug to the text of the options and not more than that.
I have put that Spacer()
in there but it gets compressed all the way by the Picker.
How can I make it so the Picker's width is sized so fit its content and not more than that? I want the "Test text" on the left, space in the middle and the segment control on the right. I don't want the segment control to take the entire width of the cell.
Upvotes: 2
Views: 281
Reputation: 36314
try something like this to put "...the "Test text" on the left, space in the middle and the segment control on the right.":
HStack {
Text("Test text")
Spacer()
Picker("Test picker", selection: $selectedAccessType, content: {
Text("option1").tag(0)
Text("option2").tag(1)
})
.pickerStyle(SegmentedPickerStyle())
.fixedSize(horizontal: true, vertical: false) // <-- here
// .fixedSize() // <-- or this
}
Upvotes: 3