I'm messing about with a grid where I want the first column to shrink to the width of the content and the second column to fill the remaining space. Using IB and layout constraints this sort of thing is relatively simple, but it's got me stumped in SwiftUI.
Basically I have code like this:
@State var sliderValue1: Float = 0.5
@State var sliderValue2: Float = 0.25
var body: some View {
let col1 = GridItem(alignment: .leading)
let col2 = GridItem()
LazyVGrid(columns: [col1, col2]) {
Text("Short").border(Color.green)
Slider(value: $sliderValue1, in: 0.0 ... 1.0, step: 0.25).border(Color.red)
Text("Rather long").border(Color.green)
Slider(value: $sliderValue2, in: 0.0 ... 1.0, step: 0.25).border(Color.red)
}
.border(Color.blue)
}
As you can see the two columns are the same size which is not what I want. What I'm trying to do is shrink the first column's width to that of the "Rather long" label. I can't specify a size using .fixed(...)
and I've tried all sorts of .flexible(...)
definitions with no luck.
Anyone got a column to resize to fit the content?