0

I'm trying to align the first line of texts with .firstTextBaseline however doesn't seem to work with LazyHStack. Similarly using AlignmentGuide also doesn't seem to be working. Am i missing something with understanding LazyHStacks?

HStack LazyHStack
enter image description here enter image description here

Sample code:

struct ContentView: View {
var body: some View {
        LazyHStack(alignment: .firstTextBaseline) {
            VStack {
                Color.green
                    .frame(width: 100, height: 100)
                Text("blah blah")
            }
//                .alignmentGuide(VerticalAlignment.firstTextBaseline) { d in  // this also has no effect
//                    d[.top]
//                }

            Text("---- Center Line ----")


            VStack {
                Color.green
                    .frame(width: 100, height: 100)
                Text("blah blah blah \nblah")
                    .fixedSize()
            }

        }
        .background {
            Color.blue
        }
    }
}
Wy th
  • 33
  • 5

1 Answers1

0

What you could do, which seems more of a hack, than a real solution, is to use it as an HStack, but put everything inside a LazyVStack like so:

LazyVStack {
    HStack(alignment: .firstTextBaseline) {
        VStack {
            Color.green
                .frame(width: 100, height: 100)
             Text("blah blah")
        }
                
                
        Text("---- Center Line ----")
                
                
        VStack {
            Color.green
                .frame(width: 100, height: 100)
            Text("blah blah blah \nblah")
                .fixedSize()
        }
                
    }
    .background {
        Color.blue
    }
}
bennyyy999
  • 80
  • 1
  • 5