1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| // // ContentView.swift // tableView // // Created by junyao on 2023/4/22. //
import SwiftUI import TabBar
struct ContentView: View { enum TabItems: Int { case editor, notes, share, settings } @State private var selectedTab = 0 var body: some View { TabView(selection: $selectedTab) { EditorView() .badge(10) .tabItem { Label("对话", systemImage: "pencil.circle") Text("Editor") }.tag(TabItems.editor.rawValue) .onTapGesture { selectedTab = TabItems.editor.rawValue } NotesView() .tabItem { Label("指令库", systemImage: "note.text") Text("Notes") }.tag(TabItems.notes.rawValue) .onTapGesture { selectedTab = TabItems.notes.rawValue } SettingsView() .tabItem { Label("设置", systemImage: "gearshape") Text("Settings") }.tag(TabItems.settings.rawValue) .onTapGesture { selectedTab = TabItems.settings.rawValue } }.accentColor(.black).tint(.black) .onAppear(perform: { //修改未选择的项的颜色 UITabBar.appearance().unselectedItemTintColor = UIColor(Color.gray) }) } }
struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }
|
相关
SwiftUI——如何修改TabView的各种属性(包括tabItem的属性),例如颜色、位置、大小等