Posts

Post not yet marked as solved
0 Replies
1.9k Views
Hi, I am updating our app to use the UITabBarAppearance() to set the standardAppearance and scrollEdgeAppearance for our tab bar, since compiling with Xcode 13 on iOS 15 devices breaks our ui when using the old approach. However I am running into a problem with setting the badge ui on the tab bar items. I have two tabs that need to be able to show a badge, and we want the badge ui to be different. One tabs badge should have a black background with white text, and the other tabs badge should have a grey background with black text. This used to work by just setting the tabBarItem.badgeColor and tabBarItem.setBadgeTextAttributes() but that no longer works with UITabBarAppearance(). So far I have only found a way to set the badge background and text color generally for all tabs by setting the stackedLayoutAppearance: private func setupTabBar() { let tabBar = UITabBar.appearance() let tabBarAppearance = UITabBarAppearance() tabBarAppearance.configureWithOpaqueBackground() tabBarAppearance.backgroundColor = .white let tabBarItemAppearance = UITabBarItemAppearance() tabBarItemAppearance.normal.badgeTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] tabBarItemAppearance.normal.badgeBackgroundColor = UIColor.black tabBarAppearance.stackedLayoutAppearance = tabBarItemAppearance tabBar.standardAppearance = tabBarAppearance if #available(iOS 15, *) { tabBar.scrollEdgeAppearance = tabBarAppearance } } So I wanted to ask if it is even still possible to set individual badge colors on the tab bar items?
Posted Last updated
.