0

I'm putting a ForEach inside an HStack. I hope each element in ForEach will keep its original width and the parent HStack should overflow the screen as needed. However, this results in that the parent HStack fits the width of the screen and each element inside ForEach get narrowed down into 1/n * screenWidth.

Sample Code:

HStack(alignment: .bottom) {
  ForEach(data, id: \.id) { element in
    SomeView(data: element)
  }
}

I could achieve a similar effect by putting the parent HStack in a ScrollView. But what if I don't want the scroll behavior? I wonder how ScrollView achieve this infinity width?

1
  • If you don't want scroll behavior, what do you want? Just the last visible view to be clipped? Your question is not clear about that. Commented Jun 6, 2021 at 10:52

1 Answer 1

0

Whatever you are trying to achieve, doing that results into breaking the ui.

Take an image for example, put it into a VStack and don't make it resizable. It will overflow the view. Anything you place in that VStack will overflow too and won't align within the screens boundaries.

So your best bet is to go with a ScrollView and disable the scrolling as discussed here: How to only disable scroll in ScrollView but not content view?

Sign up to request clarification or add additional context in comments.

1 Comment

While the link might answer the question you should post there relevant code in the answer section. Link break over time making answers obsolete.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.