0

I'm trying to align some content inside a ScrollView. I would like to get part of this content centered and another part aligned to the leading of my screen. I can't understand why my following code isn't working, it seems that my content is centered and doesn't take the whole width. I did try to set the width, but none has worked. Any idea on how I could keep my Text("center") centered and get my hello's list to the left ?

Screenshot

Here is my current code :

struct ReportView: View {
    var body: some View {
        NavigationView {
            ScrollView(.vertical) {
                VStack(alignment: .center) {
                    Text("centered")
                }

                VStack(alignment: .leading) {
                    ForEach(1...10, id: \.self) { value in
                        Text("hello \(value)")
                    }
                }
            }
            .navigationTitle(L10n.Tab.Reports.item)
        }
    }
}
Q. Eude
  • 841
  • 11
  • 24

1 Answers1

0

Put your content inside Hstack and add a Spacer:

ForEach(1...10, id: \.self) { value in
    HStack {
        Text("Hello \(value)")
        Spacer()
    }
}
Nicolas M.
  • 360
  • 6
  • 12