I’m trying to present a list of buttons that represent people within an HStack to save vertical space on an iPhone. But when too many options are presented, the button label begins to appear in a vertical line.
What I'm trying to achieve is a horizontally arranged list of dynamically sized buttons (the size being based on the person's name - could be 'Ted' or could be 'Archduke Ferdinand the IV'). But if a button that would go in the HStack would cause the rest of the buttons to no longer be intact (meaning the name has to be split across 2 or more lines to fit the screen), I am trying to get it to instead start a new 'line' (almost as if there's a new HStack) so that the buttons maintain their readability.
This image is exactly what I'm not trying to achieve but is a good example of the text being split across multiple lines:
To be clear, the buttons should be of a variable width (again, based on the length of the person's name) but should be of a constant height (based on the default text size).
I've tried setting a few different view modifiers on the HStack to work around this, like: .fixedWidth(horizontal: true, vertical: false)
and .lineLimit(nil)
but as I'm sure most of you can tell, that only affects the text of the buttons, not the button arrangement (I'm getting desperate at this point).
I'm sure that I'm just being very thick and the solution is obvious, but I've been working at this for a day now. I've been all over StackOverflow, Hacking with Swift, Coding with Chris, etc. and I just can't find anything that gets at this issue. A lot of stuff that's close, but not quite there.