// // MainTabView.swift // duduji // // Created by ching on 2023/5/7. // import SwiftUI struct MainTabView: View { @State private var selectedIndex = 0 var body: some View { TabView(selection: $selectedIndex) { TimeLineTabView() .onTapGesture { self.selectedIndex = 0 } .tabItem { Label("时间线", systemImage: "rectangle.stack") } .tag(0) NotificationTabView() .onTapGesture { self.selectedIndex = 1 } .tabItem { Label("通知", systemImage: "bell.fill") } .tag(1) TimeLineView() .onTapGesture { self.selectedIndex = 2 } .tabItem { Label("探索", systemImage: "magnifyingglass") } .tag(2) TimeLineView() .onTapGesture { self.selectedIndex = 3 } .tabItem { Label("私信", systemImage: "tray.fill") } .tag(3) TimeLineView() .onTapGesture { self.selectedIndex = 4 } .tabItem { Label("个人主页", systemImage: "person.circle.fill") } .tag(4) } .navigationTitle(title(for: selectedIndex)) // } // .navigationBarTitleDisplayMode(.inline) } func title(for tab: Int) -> String { switch tab { case 0: return "Home" case 1: return "Notification" case 2: return "Explore" case 3: return "Message" case 4: return "Profile" default: return "" } } } struct MainTabView_Previews: PreviewProvider { static var previews: some View { MainTabView() } }