I have the text "Groups" and I want to use NavigationLink to connect it to my GroupsPage subpage and take the user there when they click the Groups text.
Edit: This is how it looks with the added VStack
This is my whole file(edit):
import SwiftUI
struct LaunchPage: View {
var body: some View {
NavigationStack{
GeometryReader {geo in
VStack{
ScrollView{
ZStack {
Color.clear
.background(.ultraThinMaterial)
NavigationLink("Groups", destination: GroupsPage())
.font(.largeTitle.weight(.bold))
.frame(maxWidth:.infinity, alignment: .leading)
.padding(.leading, 20)
.foregroundColor(.black)
.frame(height: 70)
.frame(maxHeight: .infinity, alignment: .top)
}
VStack {
Spacer()
Image("carpooly-high-resolution-logo")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: geo.size.width * 2.0, height: geo.size.width * 1.5)
.offset(y:-88)
.offset(x:-200)
.padding(.top, 100)
}
}.border(.red)
}
}
.navigationBarHidden(true)
}
}
}
struct GroupsPage: View{
var body: some View {
Text("Groups")
.font(.largeTitle)
.fontWeight(.bold)
.foregroundColor(Color.green)
.multilineTextAlignment(.center)
.padding(/*@START_MENU_TOKEN@*/.all, 2.0)
.frame(width: 200.0, height: 50.0)
.navigationBarTitle("Group Page")
}
}
struct CalendarPage: View{
var body: some View {
Text("Calendar")
.font(.largeTitle)
.fontWeight(.bold)
.foregroundColor(Color.green)
.multilineTextAlignment(.center)
.padding(/*@START_MENU_TOKEN@*/.all, 2.0)
.frame(width: 200.0, height: 50.0)
.navigationBarTitle("Calender Page")
}
}
struct LaunchPage_Previews: PreviewProvider {
static var previews: some View{
LaunchPage()
}
}
I have tried various types of navigation links and have also tried making the text a button. The text remained just text and did not navigate me to the GroupsPage subpage where I currently am displaying filler text. Thank you in advance!
To
... make my text navigate me to a subpage
Here is my working test code using
NavigationLink(...)
that shows how to display the text "Groups" and navigate to theGroupPage
when clicked/tapped.On MacOS 14.2, using Xcode 15.1, tested on real ios17 devices (not Previews) and MacCatalyst. It could be different on older systems.
Or, using your previous question code (with minor changes to the size of the star):
EDIT-1
Your problem is that the
ScrollView
overlaps/covers theNavigationLink
. You can see this if you add a.border(.red)
to it, as shown in the example code.You can add a
VStack
as shown to make theNavigationLink
work, or other avenue to suit your purpose.