struct MainView: View {
@Stateprivatevarselection:Tab= .emoji
enumTab{
casegame
casehome
caseemoji
}
init() {
//设置未选中颜色
UITabBar.appearance().unselectedItemTintColor = .green
}
varbody:someView{
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)
}
}
网友评论