'Setting a UITabBarAppearance breaks UITabBarItem appearance proxy font size when selecting tabs

The following, which sets the title text appearance proxy to use a big font, works as expected, and the UITabBarItems retain their big font when you select them:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        // UITabBar.appearance().standardAppearance = UITabBarAppearance()
                
        let bigFont = UIFont.systemFont(ofSize: 20)
        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: bigFont], for: .normal)
        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: bigFont], for: .selected)
        
        return true
    }

enter image description here


But when you set a UITabBarAppearance on the UITabBar appearance proxy, the font size is broken when you select tabs:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        UITabBar.appearance().standardAppearance = UITabBarAppearance()
                
        let bigFont = UIFont.systemFont(ofSize: 20)
        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: bigFont], for: .normal)
        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: bigFont], for: .selected)
        
        return true
    }

enter image description here



Question:

Does anyone know why setting a UITabBarAppearance would break the setTitleTextAttributes font size choice?


Background info:

The reason I'm using setting the standardAppearance on the UITabBar is because in my actual project I'm using the following code to retain the old look of the tab bar, and not the new one which goes transparent when there is no content on the screen (and messes up the app design).

If there is a way to achieve that without breaking the font size, then that could be a potential "fix" :)

if #available(iOS 13.0, *) {
    let tabBarAppearance = UITabBarAppearance()
    tabBarAppearance.configureWithDefaultBackground()
    UITabBar.appearance().standardAppearance = tabBarAppearance
    if #available(iOS 15.0, *) {
        UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source