英文:
Why is the UITabBarController default background color not shown in the iOS simulator?
问题
我试图以程序方式生成一个UITabBarController
。这是我在应用程序代理中的做法:
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
}
结果是:
当我在真实设备上测试时,看起来是正常的:
我的Xcode版本是14.2,iOS模拟器版本是16.2。我的目标iOS版本是13。我重新安装了Xcode,但没有改变。这可能是什么原因?我一点头绪都没有。我还尝试了一些UITabBarController
的公共存储库示例,结果与我的代码相同。默认的选项卡栏未正确显示。
英文:
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.
答案1
得分: 1
似乎这只是模拟器的错误,因为在设备上一切正常,但在模拟器上什么都不起作用。尝试更新你的Xcode,有一个更新版本,14.3.1。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论