import SwiftUI // MARK: - Tab 枚举 enum Tab: Int, CaseIterable { case feed = 0 case me = 1 var title: String { switch self { case .feed: return "动态" case .me: return "我的" } } var iconName: String { switch self { case .feed: return "sparkles" case .me: return "person" } } var selectedIconName: String { switch self { case .feed: return "sparkles" case .me: return "person.fill" } } } // MARK: - BottomTabView 组件 struct BottomTabView: View { @Binding var selectedTab: Tab var body: some View { HStack(spacing: 0) { ForEach(Tab.allCases, id: \.rawValue) { tab in Button(action: { selectedTab = tab }) { VStack(spacing: 4) { Image(systemName: selectedTab == tab ? tab.selectedIconName : tab.iconName) .font(.system(size: 20)) .foregroundColor(selectedTab == tab ? .purple : .gray) Text(tab.title) .font(.caption2) .foregroundColor(selectedTab == tab ? .purple : .gray) } .frame(maxWidth: .infinity) } .buttonStyle(PlainButtonStyle()) } } .padding(.vertical, 12) .padding(.horizontal, 8) .background( .ultraThinMaterial, in: Rectangle() ) .overlay( Rectangle() .frame(height: 0.5) .foregroundColor(.black.opacity(0.2)), alignment: .top ) } }