Reputation: 407
So I have a LazyVGrid
that I am utilizing inside my project, but I am having an issue in getting one of my fields to align properly.
So here is the code that I have:
VStack {
LazyVGrid(columns: [GridItem(), GridItem(), GridItem(alignment: .top)], content: {
Spacer()
Image("onboarding-logo")
.renderingMode(.original)
.resizable()
.scaledToFit()
.frame(width: 120.0)
.padding()
.clipped()
.frame(alignment: .center)
.border(.red)
NavigationLink(destination: MainView().environmentObject(mainViewModel), label: {
Text("Skip")
.frame(height: .infinity, alignment: .top)
.clipped()
.padding()
.foregroundColor(Color.white)
})
})
.border(.red)
}
This outputs the following view:
How could I make the "Skip" text be in the top-right corner? As shown here:
I would like to keep all the columns "top" aligned, "logo" center/top aligned, and the "Skip" button top-right aligned, is this possible?
Upvotes: 0
Views: 497
Reputation: 154583
SwiftUI has a number of combined alignment values such as .topLeading
and .bottomTrailing
.
In your case, you want your Text in the top right corner, which is .topTrailing
for a left to right language.
Replace:
LazyVGrid(columns: [GridItem(), GridItem(), GridItem(alignment: .top)], content: {
with:
LazyVGrid(columns: [GridItem(), GridItem(), GridItem(alignment: .topTrailing)], content: {
Upvotes: 2