// // TabBarView.swift // jason // // Created by Jason on 2024/1/19. // import SwiftUI struct TabBarView: View { @AppStorage("selectedTab") var selectedTab: Tab = .home var body: some View { NavigationView { ZStack { Rectangle() .fill(Color.gray.opacity(0.2)) .ignoresSafeArea() Group { switch selectedTab { case .home: HomeView() case .explore: MallView() case .cart: CartView() case .account: UserView() } } HStack { ForEach(tabItems) { item in Button(action: { selectedTab = item.tab }, label: { VStack(spacing: 6) { Image(systemName: item.icon).resizable().frame(width: 18, height: 18) Text(item.text) .navBarText() } .frame(maxWidth: .infinity) }) .foregroundColor(selectedTab == item.tab ? Color("MainText") : Color.secondary) .shadow(color: selectedTab == item.tab ? Color.orange : Color.blue, radius: 15) } } .padding(.vertical, 12.0) .background(Color("TabBarColor").ignoresSafeArea()) .frame(maxHeight: .infinity, alignment: .bottom) .shadow(color: Color.gray.opacity(0.5), radius: 6, x: 0, y: 6) } } } } #Preview { TabBarView() }