Instance Method インスタンスメソッド

tabItem(_:)

Sets the tab bar item associated with this view. このビューと結びつけられたタブバー項目を設定します。

Declaration 宣言

func tabItem<V>(_ label: () -> V) -> some View where V : View

Parameters パラメータ

label

The tab bar item to associate with this view.

Discussion 議論

Use tabItem(_:) to configure a view as a tab bar item in a TabView. The example below adds two views as tabs in a TabView:


struct View1: View {
    var body: some View {
        Text("View 1")
    }
}


struct View2: View {
    var body: some View {
        Text("View 2")
    }
}


struct TabItem: View {
    var body: some View {
        TabView {
            View1()
                .tabItem {
                    Label("Menu", systemImage: "list.dash")
                }


            View2()
                .tabItem {
                    Label("Order", systemImage: "square.and.pencil")
                }
        }
    }
}

A screenshot of a two views configured as tab items in a tab