Created
July 10, 2024 05:07
-
-
Save pookjw/2465a3e7b5358cb4ab052e9dd4a97f3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
Author
pookjw
commented
Jul 10, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment