Biggy Boy
Biggy Boy

Reputation: 51

SwiftUI LazyHGrid rows centering

I have an array with 13 items and I'm trying to build LazyHGrid with two rows, 7 in the first and 6 in the second row. The second row must be centered inside LazyHGrid. Like this:

show image

I set alignment to GridItem to .center like this:

LazyHGrid(rows: [GridItem(.flexible()), GridItem(.flexible(), alignment: .center)], alignment: .center, spacing: 20) {
    ForEach(0..<13) { number in
        Letter(text: self.tray[number], index: number, isTop: true, onChanged: self.letterMoved, onEnded: self.letterDropped)
    }
}

But anyway it doesn't help and my result looks like this:

my current result image

Is it possible to build LazyHGrid in this way?

Upvotes: 4

Views: 1120

Answers (1)

Biggy Boy
Biggy Boy

Reputation: 51

Solved this issue by adding custom offset to each item

Upvotes: 1

Related Questions