Fit SwiftUI grid columns to the contents

My grids expand widthways to take up all the space it can. I can stick it in a frame and limit the size. But is there a way to get the columns to shrink to fit the contents plus padding? That would be neater, and probably more robust if the text changes size.

FWIW most of my grids contain only text, and I don't use a lot of columns.

Answered by Richard_Kirk in 732883022

I think I have solved this.

Grids don't normally expand to fill the whole width, but I had a Divider() in my one and those can do. The fix was...

Divider()
 .gridCellUnsizedAxes(.horizontal)

                           

Accepted Answer

I think I have solved this.

Grids don't normally expand to fill the whole width, but I had a Divider() in my one and those can do. The fix was...

Divider()
 .gridCellUnsizedAxes(.horizontal)

                           

Fit SwiftUI grid columns to the contents
 
 
Q