struct ContentView: View {
private enum Item: Int, Tabbable {
case first = 0
case second
case third
var icon: String {
switch self {
case .first: return "house"
case .second: return "magnifyingglass"
case .third: return "person"
}
}
var title: String {
switch self {
case .first: return "First"
case .second: return "Second"
case .third: return "Third"
}
}
}
@State private var selection: Item = .first
@State private var visibility: TabBarVisibility = .visible
var body: some View {
TabBar(selection: $selection, visibility: $visibility) {
Button {
withAnimation {
visibility.toggle()
}
} label: {
Text("Hide/Show TabBar")
}
.tabItem(for: Item.first)
Second()
.tabItem(for: Item.second)
Text("Third")
.tabItem(for: Item.third)
}
.tabBar(style: CustomTabBarStyle())
.tabItem(style: CustomTabItemStyle())
}
}
struct ContentSystemTabView: View {
var body: some View {
TabView {
Text("First")
.tabItem {
Text("first")
}
Second()
.tabItem {
Text("second")
}
}
}
}
struct Second: View {
init() {
print("init...")
}
var body: some View {
Text("Second")
}
}
You will find the difference between TabView.
You will find the difference between TabView.