Tuesday, May 31, 2022

SwiftUI Equal and Ideal Sizes

Matthias Maurberger (via SwiftUI Weekly):

One example that illustrates this quite well is when you want to make all children of a VStack as wide as the widest child. Sounds like it should be straightforward. But it’s not. It’s a surprisingly hard problem.

[…]

First, we’ll wrap each Button’s Text label in a .frame modifier with maxWidth: .infnity. That alone only solves our problem if we want our stack of buttons to occupy the full width it was given. If we want the stack of buttons to be as wide as it needs to be, we’ll need to make a second adjustment: apply the fixedSize modifier to the VStack.

Previously:

Comments RSS · Twitter

Leave a Comment