Center Item Inside Horizontal Stack

后端 未结 4 579
暗喜
暗喜 2020-12-02 02:34

If I have 3 items inside a Horizontal Stack, I thought I could do something like this:

HStack{

      Text(\"test\")

      Spacer()

      item2()

      Sp         


        
4条回答
  •  抹茶落季
    2020-12-02 03:25

    I had the same problem and the solution from @Asperi works, but i had problems with multiline texts and some performance issues if i use it in a list.

    The following solution solved all the problems.

    HStack(alignment: .center) {
      Text("test")
          .frame(maxWidth: .infinity)
      item2()
      Text("test")            
          .frame(maxWidth: .infinity)
    }
    

提交回复
热议问题