はじめに
SwiftUI-Introspect
を使ってSwiftUIではできないことをサポートしてもらいます。
ライブラリのインストール
全体的な流れはこちらを参考にしてください
サンプルアプリ
実装
import SwiftUI
import SwiftUIIntrospect
struct ContentView: View {
@State private var isHidden = false
var body: some View {
TabView {
Button {
isHidden.toggle()
} label: {
Text("Tab1")
}
.tabItem {
Label("1", systemImage: "1.circle.fill")
}
Button {
isHidden.toggle()
} label: {
Text("Tab2")
}
.tabItem {
Label("2", systemImage: "2.circle.fill")
}
Button {
isHidden.toggle()
} label: {
Text("Tab3")
}
.tabItem {
Label("3", systemImage: "3.circle.fill")
}
}
.introspect(.tabView, on: .iOS(.v13, .v14, .v15, .v16, .v17)) { tabView in
tabView.tabBar.isHidden = isHidden
}
}
}
おわり
SwiftUIを使う時にSwiftUI-Introspect
は必須ですね