-1

I want to create a VStack of many Texts with 20 points of spacing between each Text. I want my VStack to be aligned to left side of the screen(or leading side of parent View).

Mehdi
  • 1,192
  • 1
  • 9
  • 21
arsalan_h
  • 41
  • 4
  • 2
    Welcome to StackOverflow. Please show what research you've undertaken, what you've already tried, what didn't work, code samples etc. Read [ask] and [mcve] and update your question. – Ashley Mills Oct 01 '19 at 12:37

2 Answers2

5

Try this:

struct ContentView: View {
    var body: some View {
        HStack(){
            //alignment options: .center , .leading , .trailing
            VStack(alignment: .leading, spacing: 20){
                Text("Salam")
                Text("chetori")
                Text("Arsalan")
                Text("?")
            }
            Spacer()
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

and if you want your VStack to be on right side of your screen, put the Spacer above the VStack

Mehdi
  • 1,192
  • 1
  • 9
  • 21
  • salam,khubam mersi =) this aligment: .leading is just inside VStack and still show this texts on center of the view ,i want padding this whole VStack to the left of the view – arsalan_h Oct 02 '19 at 10:53
0
VStack(alignment: .leading, spacing: 20){
    ForEach(0..<20) { i in
        HStack {
            Text("\(i)")
                .multilineTextAlignment(.leading) // needed only if your text has multiple lines
            Spacer()
        }
    }
}.padding()

And the result:

image

RiveN
  • 2,595
  • 11
  • 13
  • 26
Arnaud514
  • 21
  • 5