Search code examples
swiftuiswiftui-list

Text() doesn't expand vertically to fit multiline text


I have this in a View:

List {
GeometryReader { geo in
                        Text("\(name)")
                            .fixedSize(horizontal: false, vertical: true)
                            .lineLimit(nil)
                            .frame(width: geo.size.width, height: .infinity)
                            .font(.system(size: 26))
                            .fontWeight(.bold)
                            
                            //.font(.title)
                            //.multilineTextAlignment(.center)
                    }
}

How can I make all text visible while maintaining font size?

multiline text clipped vertically


Solution

  • Add the List in the Geometryreader and update width to .infinity

    GeometryReader { geo in
                        List {
                            Text("name")
                                .font(.system(size: 28))
                                .fontWeight(.bold)
                                .frame(width:.infinity, height: .infinity)
                                .fixedSize(horizontal: false, vertical: true)
                        }
                    }
    

    now with this code your text should be expanded vertically