UI Tab Bar Bug

Hi.

I'm trying to setup tab bar item text appearances, but the global UITabBarItem isn't accepting them

I mad a very simple assignment case, to verify this bug where this line of code fails

UITabBarItem.appearance() = UITabBarItemAppearance()

with

Cannot assign value of type 'UITabBarItemAppearance' to type 'UITabBarItem'

You can see I'm assigning to a UITabBarItemAppearance, not a UITabBarItem.

I'm making these changes as part of updating to Xcode 13, because my bar items now appear faded when normal and I want them to appear black. The font is also no longer bold. It works properly when building through any Xcode lower than 13. Before I could just do:

UITabBarItem().appeareance().setTitleTextAttributes([attributes here], for: <state>)

Now it doesn't work due to scrollEdgeAppearance becoming necessary to set. Even if I set that in a storyboard, the appearance doesn't take effect with the above code.

Replies

.appearance() returns a 'self' type, which in this case is a UITabBarItem type, hence why you cannot assign a UITabBarItemAppearance to it. Or in other words, the type of UITabBarItem.appearance() is not UITabBarItemAppearance, the types are unrelated.

If you want to customize your entire UITabBar, then assign a UITabBarAppearance (note lack of 'Item' in the name) to a UITabBar's .standardAppearance, etc. You can customize the entire tab bar for only when a specific item is assigned by assigning to the .standardAppearance, etc of a UITabBarItem. But there is no facility to customize a specific UITabBarItem separately from all the others in the modern appearance API for UITabBar.

PS: Due to implementation details for how the appearance proxy works for non-UIView conformances to UIAppearance, using the appearance proxy to set standardAppearance or scrollEdgeAppearance for a UITabBarItem will not work, and likely will result in a crash.

  • "But there is no facility to customize a specific UITabBarItem separately from all the others in the modern appearance API for UITabBar"

    So just to be clear, if I wanted to set badge color on two tab bar items, but wanted one to be black and the other to be grey, I wouldn't be able to do that while using UITabBarAppearance and UITabBarItemAppearance? Is it only the titles and images that can be individual between the tab bar items?

Add a Comment