Dynamic width cell of grid in SwiftUI

132 Views Asked by At

Hi everyone I'm having problems with a Grid and its contents. As you can see from the image, each cell expands as much as the text contained in it. It spreads too much... I would like the description (long text) to be spread across multiple lines if it exceeds a hypothetical width limit.


enter image description here


Can you tell me where I'm going wrong in my code or what kind of changes I need to make?

ScrollView(.horizontal) {
                        Grid {
                            ForEach(0..<3) { _ in
                                GridRow {
                                    VStack(alignment: .leading, spacing: 16) {
                                        VStack(alignment: .leading, spacing: 8) {
                                            Text("Lorem".uppercased())
                                                .bold()
                                                .font(.footnote)
                                            Text("Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem Lorem ")
                                                .font(.caption)
                                        }
                                    }
                                }
                                .padding(16)
                                .background(.secondary.opacity(0.1))
                                .clipShape(.buttonBorder)
                            }
                        }
0

There are 0 best solutions below