SwiftUI from entry to actual combat Chapter 2 Section 7: TabView

Related courses: http://hdjc8.com/hdjc/swiftUI/

TabView is equivalent to UITabBarController in UIKit and is used to implement tab view sets.

The tab view is located at the bottom of the screen, allowing users to quickly switch between several pages, the effect is similar to UITabBarController.

The page controlled by the tab view is inside the braces. TabView only supports label items of text, image or LayoutView, and other types of views will produce a visible blank label item.

Sample code:

var body: some View {
	TabView {
        //添加一个文本视图,作为标签视图的第一个标签项。
	    Text("The home page.")
		.font(.system(size: 36))
        //接着来设置文本视图的选项卡,只有设置了选项卡,才会在屏幕底部的选项卡列表里显示对应的标签。
		.tabItem({
		    Image(systemName: "house")
		    Text("Home") })
		.tag(0)

        //继续添加另一个文本视图,作为标签视图的第二个标签项。
	    Text("The settings page")
		.font(.system(size: 36))
		.tabItem({
		    Image(systemName: "gear")
		    Text("Settings")
		})
		.tag(1)
	}
    }

Show running results:

Guess you like

Origin blog.csdn.net/fzhlee/article/details/106105745