Scenario:
I have a login screen with a "Enter button", as the picture shown below: Login Screen. The code, in its simplest form, is:
NavigationStack{
// Contains BG and rest of elements
ZStack{
Image("LoginBG")
.resizable()
.ignoresSafeArea(.all)
VStack {
Image("")
.resizable()
.scaledToFill()
.frame(width: 150, height: 150)
.padding()
NavigationLink(destination: RootTabView().navigationBarBackButtonHidden(true)){
Text("Enter")
.frame(maxWidth: 200)
.bold()
}
.buttonStyle(.borderedProminent)
.tint(Color(red: 6/100, green: 36/100, blue: 42/100))
} // Vstack
} // ZStack
}
After clicking Enter, it takes me to a TabView, with some Items. Code as follows:
TabView {
Profile()
.tabItem {Label("Profile", systemImage: "person.crop.circle")}
MyEvents()
.tabItem {Label("My Events", systemImage: "house")}
SearchEvents()
.tabItem {Label("Search", systemImage: "magnifyingglass")}
Rating()
.tabItem {Label("Rating", systemImage: "bell")}
Settings()
.tabItem {Label("Settings", systemImage: "gear")}
}
The TabView contains, for example, the Profile view. This view looks like this: Profile Screen with title and the code is like this:
NavigationStack{
VStack {
Image("ProfileBG")
.resizable()
.clipShape(Circle())
.ignoresSafeArea(.all)
.frame(maxWidth: 100,maxHeight: 100)
.padding()
.padding()
.navigationTitle("Profile")
Text("User").bold()
Text("@AppUser")
HStack{
VStack {
Text("Events Created").bold()
Text("0")
}
Spacer()
VStack {
Text("Events Joined").bold()
Text("0")
}
}
.padding()
.frame(width: 330)
}
}
Problem:
When I navigate from Login View to the TabView, the Profile TabView item shows as follows: Profile without title bar.
As you can see, the Toolbar (or UINavigationBar in UIKit) is not appearing when I navigate from the Login screen to the TabView.
Objective:
I would like to have a customized toolbar with different background colors and titles individually in each tabItem
I have tried to set the toolbar is all the possible ways available, but either I cannot change the toolbar title when navigationBarTitleDisplayMode is set to.large. And .inline isn't my preferred one.
I've tried to look for answers in google, stack overflow, but it's not that common. Can anyone help me?
Thanks in advance.
First of all, remove
NavigationStackfrom theProfilebecause parent view has already NavigationStack. Remove navigation title from the Profile and set RootTabView's Navigation Title dynamically as below:Change the NavigationBar appearance by adding below code to your SwiftUI APP:
Output: