I am trying to generate a UITabBarController programatically. This is how I did it in application delegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
func makeItem(title: String, image: String) -> UITabBarItem {
return UITabBarItem(
title: NSLocalizedString(title, comment: ""),
image: UIImage(systemName: image),
tag: 0
)
}
firstViewController = ViewController(backgroundColor: .blue)
firstViewController.tabBarItem = makeItem(title: "First", image: "books.vertical.fill")
secondViewController = ViewController(backgroundColor: .red)
secondViewController.tabBarItem = makeItem(title: "Second", image: "books.vertical.fill")
let tabBarController = UITabBarController()
tabBarController.setViewControllers([firstViewController, secondViewController], animated: true)
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = tabBarController
window?.makeKeyAndVisible()
return true
}
The result is:

When I test this in real device it seems normal:

My Xcode version is 14.2, iOS Simulator 16.2. My target iOS version is 13. I reinstalled Xcode and it didn't change. What would be the reason of this? I have zero clue. I also tried some public repository example of UITabBarController and the result is same with my code. Default tabbar is not shown properly.
Seems like this is just a simulator bug, since on device everything works fine, but nothing works on simulator. Try updating your Xcode, there's a newer version out, 14.3.1