struct MainView: View {
@State private var selection: Tab = .emoji
enum Tab {
case game
case home
case emoji
}
init() {
//设置未选中颜色
UITabBar.appearance().unselectedItemTintColor = .green
}
var body: some View {
TabView(selection: $selection,
content: {
EmojiArtView()
.tabItem {
Image(selection == Tab.emoji ? "tabbar_home_sel" : "tabbar_home")
Text("首页")
.foregroundColor(.orange)
}
.tag(Tab.emoji)
\
EmojiViewGame()
.tag(Tab.game)
.tabItem {
Image(selection == Tab.game ? "tabbar_social_sel" : "tabbar_social")
Text("消息")
}
HomeView()
.tabItem {
Image(selection == Tab.home ? "tabbar_mine_sel" : "tabbar_mine")
Text("我的")
}
.tag(Tab.home)
})
//设置选中颜色
.accentColor(.red)
.font(.headline)
}
}