Skip to content

Instantly share code, notes, and snippets.

@pookjw
Created July 10, 2024 05:07
Show Gist options
  • Save pookjw/2465a3e7b5358cb4ab052e9dd4a97f3e to your computer and use it in GitHub Desktop.
Save pookjw/2465a3e7b5358cb4ab052e9dd4a97f3e to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
var body: some View {
TabView {
Color.red
.ignoresSafeArea()
.tabItem {
Label("Red", systemImage: "1.circle.fill")
}
.background {
TabViewCustomizationEnablerView()
}
Color.orange
.ignoresSafeArea()
.tabItem {
Label("Orange", systemImage: "2.circle.fill")
}
Color.yellow
.ignoresSafeArea()
.tabItem {
Label("Yellow", systemImage: "3.circle.fill")
}
.ignoresSafeArea()
Color.green
.ignoresSafeArea()
.tabItem {
Label("Green", systemImage: "4.circle.fill")
}
Color.blue
.ignoresSafeArea()
.tabItem {
Label("Blue", systemImage: "5.circle.fill")
}
Color.purple
.ignoresSafeArea()
.tabItem {
Label("Purple", systemImage: "6.circle.fill")
}
Color.pink
.ignoresSafeArea()
.tabItem {
Label("Pink", systemImage: "7.circle.fill")
}
Color.cyan
.ignoresSafeArea()
.tabItem {
Label("Cyan", systemImage: "8.circle.fill")
}
.ignoresSafeArea()
Color.gray
.tabItem {
Label("gray", systemImage: "9.circle.fill")
}
}
}
}
fileprivate struct TabViewCustomizationEnablerView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> ViewController {
.init()
}
func updateUIViewController(_ uiViewController: ViewController, context: Context) {
}
final class ViewController: UIViewController {
override func didMove(toParent parent: UIViewController?) {
super.didMove(toParent: parent)
var _parent: UIViewController? = parent
while let __parent: UIViewController = _parent {
if let tabBarController: UITabBarController = __parent.tabBarController {
tabBarController.customizableViewControllers = tabBarController.viewControllers
break
}
_parent = __parent.parent
}
}
}
}
#Preview {
ContentView()
}
@pookjw
Copy link
Author

pookjw commented Jul 10, 2024

Simulator Screenshot - iPhone 15 Pro Max - 2024-07-10 at 14 06 57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment