I just started learning programming SwiftUI apps for iOS.
I'm currently developing an app using SwiftUI and I've encountered an issue with the TabView component. I want to use it for my Side Menu. My TabView has 6 tabs, and I noticed that a "More" button appears at the bottom with three dots. I managed to hide this button by using .toolbarVisibility(.hidden, for: .tabBar). However, I'm still getting a "More" button in the upper left corner of the last two tabs, and I'm unable to find a way to remove it.
My code:
import SwiftUI
//Standard Color for Background
let standardColor = Color(red: 0.96, green: 0.94, blue: 0.88)
struct ContentView: View {
@State private var showMenu = false //Variable die ausgibt ob das Menu gezeigt wird @State sagt aus das es eine Var ist die aktualisert wird
@State private var selectedTab = 0
var body: some View {
NavigationStack{
/*@START_MENU_TOKEN@*//*@PLACEHOLDER=Container@*/VStack/*@END_MENU_TOKEN@*/ {
ZStack {
TabView(selection: $selectedTab){
Group{
home()
.tag(0)
.transaction {transaction in
transaction.animation = .default
}
ourdate()
.tag(1)
.transaction {transaction in
transaction.animation = .default
}
ToDoView()
.tag(2)
.transaction {transaction in
transaction.animation = .default
}
Text("Appointments")
.tag(3)
.transaction {transaction in
transaction.animation = .default
}
Text("Purchase")
.tag(4)
.transaction {transaction in
transaction.animation = .default
}
Text("Profile")
.tag(5)
.transaction {transaction in
transaction.animation = .default
}
}
//.toolbarBackground(.hidden, for: .tabBar) Braucht man nicht wenn toolbarVisibility hidden ist
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
}
sideMenuView(isShowing: $showMenu, selectedTab: $selectedTab)
}
.toolbar(showMenu ? .hidden : .visible, for: .navigationBar)
.navigationBarTitleDisplayMode(.inline)
.animation(.easeInOut , value: showMenu)
.toolbar{
ToolbarItem(placement: .topBarLeading){
Button(action:{showMenu.toggle()},
label:{
Image(systemName: "line.horizontal.3")
.foregroundColor(.black)
})
}
ToolbarItem(placement: .principal) {
let (title, imageName) = selectNavigationName(tab: selectedTab)
HStack {
Text(title)
.font(.headline)
Image(systemName: imageName)
.imageScale(.small)
.bold(true)
}
}
}
}
}
}
func selectNavigationName(tab: Int) -> (String, String) {
switch tab {
case 0:
return ("Home", "house")
case 1:
return ("Us", "heart")
case 2:
return ("ToDo", "list.bullet")
case 3:
return ("Appointments", "calendar")
case 4:
return ("Purchase", "cart")
case 5:
return ("Profile", "person.circle")
default:
return ("Home", "house")
}
}
}
#Preview {
ContentView()
.modelContainer(for: ToDo.self)
}