Layout in SwiftUI with horizontal and vertical alignment

后端 未结 6 2125
别跟我提以往
别跟我提以往 2021-02-04 09:11

I\'m trying to accomplish this layout

If I try HStack wrapped in VStack, I get this:

If I try VStack wrapped in HStack, I get this:

6条回答
  •  轮回少年
    2021-02-04 09:40

        HStack{
            Image(model.image)
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: 10, alignment: .leading)
            VStack(alignment: .leading) {
                Text("Second column ")
                Text("Second column -")
            }
            Spacer()
            Text("3rd column")
        }
    

    1- first column - image

    2- second column - two text

    3- the float value

    Spacer() - Play with Spacer() -> above example image and vstack remains together vertical align for all rows, just put spacer for the views you want to do in another vertical alignment / column VStack(alignment: .leading. - this is importent to make alignment start

提交回复
热议问题