Reputation: 7250
Up to Xcode 15 and iOS 17, it was easy to change the tab bar item badge color in UIKit using this kind of code:
private func setupBadgeColors(item: UITabBarItem?, backgroundColor: UIColor, textColor: UIColor) {
guard let item
else { return }
item.badgeColor = backgroundColor
item.setBadgeTextAttributes([.foregroundColor: textColor], for: .normal)
}
Unfortunately this is not effective anymore with Xcode 16 and iOS 18.
I can change the aspect of all the badges of the tab bar, using the badgeBackgroundColor
and badgeTextAttribute
of a UITabBarItemStateAppearance
within a UITabBarItemApperance
of a UITabBarAppearance
.
I can even customize the appearance of all the badges according to the selected item by updating the specific UITabBarAppearance
of each item.
Unfortunately I wish to find a way to customize the badge of each item specifically.
Thank you for your help.
Upvotes: 3
Views: 380
Reputation: 83
Pretty sure this is an Apple bug with the new tab bar. If you split screen your app into a compact layout, the old tab bar appears and the attributes work as expected.
Another semi-related issue is the badge clips if it's the last item in the tab bar.
I submitted a Feedback Assistant ticket for the two issues.
Upvotes: 0