简体   繁体   中英

How to create a shared navigation bar to inter-navigate among multiple views in SwiftUI?

I would like to navigate among screens A, B, and C by tapping the corresponding button in a shared navigation bar at the bottom of every screen. How can I create such a toolbar to achieve this inter-navigability among screens?

在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

You would use a TabView {...} to accomplish this. Effectively you instantiate your views inside of the TabView then add an item modifier to each view.

var body: some View {
    TabView {
        Text("A")
            .tabItem { Text("A") }
        Text("B")
            .tabItem { Text("B") }
        Text("C")
            .tabItem { Text("C") }
    }
}

What this code does: https://i.stack.imgur.com/CKBHm.gif

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM