Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 15 UITabBarController's tabBar background color turns black

tabBar.barTintColor can't be changed in iOS 15 beta 4.

Background. We have an app in App Store and each year before the new iOS major version releases we download the iOS beta and test our app to fix the issues beforehand.

Our problem. This year when testing in iOS 15 beta 4 we found the UITabBarController's tabBar background color turns black and makes the item (both icon and title) hard to read. In our code we had self.tabBar.barTintColor = .white and this line of code doesn't work in iOS 15.

Our attempts. I search online and found a similar, not exactly the same, issue reported, https://developer.apple.com/forums/thread/682420. And I tried standardAppearance but this is not the solution since with appearance I can't change tabBar.tintColor.

like image 912
Zhengqian Kuang Avatar asked Aug 06 '21 23:08

Zhengqian Kuang


Video Answer


3 Answers

I had the same issue and found the same link that is in your question. I used the same approach for the tab bar.

This is the code i am using and it works perfectly.

if #available(iOS 15.0, *) {
   let appearance = UITabBarAppearance()
   appearance.configureWithOpaqueBackground()
   appearance.backgroundColor = customColor
   
   self.tabController.tabBar.standardAppearance = appearance
   self.tabController.tabBar.scrollEdgeAppearance = view.standardAppearance
}
like image 118
anon_nerd Avatar answered Oct 18 '22 19:10

anon_nerd


Similar to an answer above but with a fix for view not being recognised if you are using custom classes:

if #available(iOS 15.0, *) {
    let appearance = UITabBarAppearance()
    appearance.configureWithOpaqueBackground()
    appearance.backgroundColor = .white
    tabBar.standardAppearance = appearance
    tabBar.scrollEdgeAppearance = tabBar.standardAppearance
}
like image 35
Charlie Seligman Avatar answered Oct 18 '22 20:10

Charlie Seligman


Create a UITabBarAppearance like this to maintain the same visual behavior as previous iOS versions:

@available(iOS 15.0, *)
private func updateTabBarAppearance() {
    let tabBarAppearance: UITabBarAppearance = UITabBarAppearance()
    tabBarAppearance.configureWithOpaqueBackground()
    
    let barTintColor: UIColor = .white
    tabBarAppearance.backgroundColor = barTintColor
    
    updateTabBarItemAppearance(appearance: tabBarAppearance.compactInlineLayoutAppearance)
    updateTabBarItemAppearance(appearance: tabBarAppearance.inlineLayoutAppearance)
    updateTabBarItemAppearance(appearance: tabBarAppearance.stackedLayoutAppearance)
    
    self.tabBar.standardAppearance = tabBarAppearance
    self.tabBar.scrollEdgeAppearance = tabBarAppearance
}

@available(iOS 13.0, *)
private func updateTabBarItemAppearance(appearance: UITabBarItemAppearance) {
    let tintColor: UIColor = .red
    let unselectedItemTintColor: UIColor = .green
    
    appearance.selected.iconColor = tintColor
    appearance.normal.iconColor = unselectedItemTintColor
}
like image 23
Daniel Storm Avatar answered Oct 18 '22 18:10

Daniel Storm