To make two (or more) objects the same height in SwiftUI, just make them all .frame(maxHeight: .infinity)
and then make the container they’re in .fixedSize(horizontal: false, vertical: true)
.
In this instance, ‘.fixedSize()
’ really means ‘minimum size’. So we’re making the container as short as it can be, while still fitting all the items inside it. Then we make the items as big as they can be, within that container.
To make multiple items the same width, it’s the same idea. Each item is .frame(maxWidth: .infinity)
and the container they’re in is .fixedSize(horizontal: true, vertical: false)
.
So the container is as narrow as it can be while still fitting the contents, and then the contents are as wide as they can be within that container.
Thanks to Becky Hansmeyer via Paul for this clean, simple technique.