-1

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:

enter image description here

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.

  • See [SwiftUI HStack with Wrap](https://stackoverflow.com/q/58842453/20386264) – Benzy Neez Aug 18 '23 at 07:37
  • Ps. It wasn't me that downvoted the question, but I expect the hit-and-run downvoter would have liked to see an [MRE](https://stackoverflow.com/help/minimal-reproducible-example) – Benzy Neez Aug 18 '23 at 07:48
  • Well, in this case, it's not a problem with my code. It's an issue with understanding how to implement a concept. What code would I show? The code that I am using in the mean time that is nothing like what I'm looking for? Then people would just get upset that it's irrelevant. – tjmcbutters Aug 18 '23 at 13:10
  • Looks like the first comment has link to what you're looking for. If that doesn't work, can you clarify what's different about what you're trying to achieve? – jnpdx Aug 19 '23 at 16:34

0 Answers0