[ad_1]
I’ve a LazyVGrid inside a NavigationView that consists of a 2 x N grid of things. Every merchandise comprises some textual content of various size and I need them to be all the identical top as the most important merchandise.
Here is a model of my code that may be copied and pasted right into a SwiftUI Playground:
import SwiftUI
import PlaygroundSupport
struct TileGridView: View {
personal var gadgets: [GridItem] {
Array(
repeating: GridItem(
.adaptive(minimal: 150),
spacing: 10
),
rely: 2
)
}
var physique: some View {
NavigationView {
LazyVGrid(columns: gadgets, spacing: 10) {
TileCellView(
textual content: "Lorem Ipsum"
)
TileCellView(
textual content: "Lorem Ipsum Dolem"
)
TileCellView(
textual content: "Lorem ipsum dolor sit amet"
)
TileCellView(
textual content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit,"
)
TileCellView(
textual content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor"
)
}
.padding(.horizontal)
.navigationTitle("")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Picture(systemName: "checkmark")
}
ToolbarItem(placement: .navigationBarTrailing) {
Picture(systemName: "checkmark")
}
}
}.navigationViewStyle(.stack)
}
}
struct TileCellView: View {
@State personal var isSelected: Bool = false
let textual content: String
var physique: some View {
ZStack {
Textual content(textual content)
.padding()
.body(maxWidth: .infinity)
.background(
RoundedRectangle(cornerRadius: 25, fashion: .steady)
.foregroundColor(.blue)
)
.contentShape(Rectangle())
.onTapGesture {
isSelected = true
}
NavigationLink(
isActive: $isSelected,
vacation spot: {
Textual content("hi")
},
label: {
EmptyView()
}
).hidden()
}
}
}
PlaygroundPage.present.setLiveView(TileGridView())
Now I attempted so as to add a PreferenceKey to TileGridView to seek out the body top of the most important merchandise however I could not get it working. Does anybody know learn how to make this work? Thanks!
[ad_2]
