美文网首页
swiftUI TabView

swiftUI TabView

作者: 大鹏你我他 | 来源:发表于2021-11-19 18:42 被阅读0次

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)

    }

}

相关文章

网友评论

      本文标题:swiftUI TabView

      本文链接:https://www.haomeiwen.com/subject/qcdetrtx.html