Tuesday, September 1, 2026
HomeiOS Developmentios - SwiftUI Make LazyVGrid Width Fill The display Inside HStack

ios – SwiftUI Make LazyVGrid Width Fill The display Inside HStack

[ad_1]

I attempt to have three LazyVGrid inside HStack and each has the width of the display, so the center one will seem and the opposite two as soon as will grew to become on the left and proper of the display (as proven within the image beneath), the issue that it isn’t match on all iPhone sizes, in case you have any thought hoe to repair this please share it.

The Code

@State non-public var numbers = [[1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7], [1, 2, 3, 4, 5, 6, 7]]
non-public let columns = Array(repeating: GridItem(.versatile(minimal: 41, most: .infinity)), rely: 7)

var physique: some View {
    HStack(spacing: 10) {
        ForEach(numbers, id: .self) { numberArray in
                LazyVGrid(columns: columns, alignment: .heart, spacing: 0, pinnedViews: []) {
                    ForEach(numberArray, id: .self) { quantity in
                        Textual content("(quantity)")
                            .background(.blue.opacity(0.3))
                    }
                }
                .body(maxWidth: .infinity)
                .background(.blue.opacity(0.1))
        }
    }
}

The view on iPhone 8

enter image description here

The view on iPhone 13 Professional Max

enter image description here

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments