4

I've implemented a vertical scroll view (using List) containing two horizontal scroll views (using ScrollViews). The UI currently looks like this:

Here's the relevant code I've written to produce above UI:

NavigationView {
    List {
        VStack(alignment: .leading) {
            CategoryRow(...)
            CategoryRow(...)
            Spacer()
        }
        .listRowInsets(EdgeInsets())
        .navigationBarTitle(Text("Featured"))
    }
}

Inside each CategoryRow, there's an HStack embedded inside a ScrollView.
When introducing a padding on the left & right edges, I get this result:

As you can see, as a result of the padding, the horizontal scroll views are cut-off.

Question

Is there a way to have the horizontal scroll views over-scroll past their boundaries?
The result I am looking for is that there is padding on the left of the scroll views when the scroll offset is 0 and padding on the right when the scrolling all the way to the right.

In UIKit, I did this by setting the contentOffset of the collection view...

9
  • I am not sure it is clear for me what the result do you expect. Do you won't to automatically scroll to some item onAppear? Commented Jun 9, 2019 at 13:07
  • Remove the padding from the right side Commented Jun 9, 2019 at 13:09
  • @DenFav I've updated my post. Does that make any sense? Commented Jun 9, 2019 at 13:10
  • @jsbeginnerNodeJS If I remove the padding on the right and scroll all the way to the right, the last item will have no padding on the right, but be on the border of the screen directly. Commented Jun 9, 2019 at 13:11
  • What about adding padding on the right side in the row itself. Commented Jun 9, 2019 at 13:13

1 Answer 1

9

Add the padding modifier to your HStack inside the RowView

.padding(.horizontal, 20)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.