3

Nested horizontal ScrollView has invisible padding from the top. I've tried to add ".padding(.top, 0)" for the ScrollView and for the content, but it doesn't work. Is it a bug or it is possible to remove this padding?

VStack(alignment: .leading) {
      Text("Text one")
      Text("Text two")
      ScrollView(.horisontal, showsIndicators: false) {
      Text("Text with strange top padding")
    }
}.padding(.horizontal)

1 Answer 1

4

I don't know what is ScrollingView but with standard ScrollView provided example works well (tested with Xcode 11.2 / iOS 13.2)

Here is a demo with added border around scroll view for better visibility

struct TestHorizontalScrollView: View {
    var body: some View {
        VStack(alignment: .leading, spacing: 0) {
              Text("Text one")
              Text("Text two")
              ScrollView(.horizontal) {
                Text("Text with strange top padding")
            }.border(Color.red)
        }.padding(.horizontal)
    }
}

enter image description here

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

3 Comments

Sorry, that was a typo. Do you see the gap between the "Text two" and the text inside the ScrollView? This is what I talked about.
@yoprst, ah that one.. then you need just specify explicit spacing in VStack, because if none then system selects default between each pair of sibling views (and no padding hardcoding as you accepted).
True, vertical view has weird padding as well. How did you solved it in the end?

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.