Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI horizontal ScrollView has invisible padding

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)
like image 595
yoprst Avatar asked May 09 '26 19:05

yoprst


1 Answers

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

like image 184
Asperi Avatar answered May 11 '26 10:05

Asperi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!