iOS 15 UITabBarController的选项卡栏背景颜色变为黑色

人气:440 发布:2022-10-16 标签: ios swift ios15 uitabbarcontroller uitabbar

问题描述

tabBar.barTintColor在iOS 15测试版4中无法更改。

背景。我们在App Store中有一个应用程序,每年在新的iOS主要版本发布之前,我们都会下载iOS测试版,并测试我们的应用程序以提前修复问题。

我们的问题。今年,当在iOS15beta4中测试时,我们发现UITabBarController的选项卡栏背景颜色变黑,使得项目(图标和标题)难以阅读。在我们的代码中,self.tabBar.barTintColor=.White,这行代码在iOS 15中不起作用。

我们的尝试。我在网上搜索,发现一个相似但不完全相同的问题报告,https://developer.apple.com/forums/thread/682420。我尝试了standardAppearance,但这不是解决方案,因为使用appearance我无法更改tabBar.tintColor

推荐答案

我遇到了相同的问题,并且找到了您问题中的相同链接。我对选项卡栏使用了相同的方法。

这是我正在使用的代码,它工作正常。

if #available(iOS 15.0, *) {
   let appearance = UITabBarAppearance()
   appearance.configureWithOpaqueBackground()
   appearance.backgroundColor = customColor
   
   self.tabController.tabBar.standardAppearance = appearance
   self.tabController.tabBar.scrollEdgeAppearance = view.standardAppearance
}

533