Align text as leading in ScrollView - SWIFTUI

前端 未结 1 1683
醉酒成梦
醉酒成梦 2021-01-24 16:00

I have a ScrollView:

    ScrollView {
        VStack (alignment: .leading) {
            Text("\\(userData.username), \\(userData.age)")
           


        
相关标签:
1条回答
  • 2021-01-24 16:26

    By default stack container is tight to content, so alignment has no effect.

    Here is possible solution

    ScrollView {
        VStack (alignment: .leading) {
            Text("\(userData.username), \(userData.age)")
                .fontWeight(.semibold)
                .font(Font.system(size:30))
        }.frame(maxWidth: .infinity, alignment: .leading) // << make screen-wide !!
    }
    
    0 讨论(0)
提交回复
热议问题