UITabBarController在iOS模拟器中默认的背景颜色为什么不显示?

huangapple go评论85阅读模式
英文:

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
}

结果是:

UITabBarController在iOS模拟器中默认的背景颜色为什么不显示?

当我在真实设备上测试时,看起来是正常的:

UITabBarController在iOS模拟器中默认的背景颜色为什么不显示?

我的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:

UITabBarController在iOS模拟器中默认的背景颜色为什么不显示?

When I test this in real device it seems normal:

UITabBarController在iOS模拟器中默认的背景颜色为什么不显示?

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

huangapple
  • 本文由 发表于 2023年6月15日 18:14:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76481480.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定