iOS 13设置 tabbar字体


iOS12

单独设置每个tabBarItem
vc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor :UIColor.red ,NSAttributedString.Key.font:UIFont .systemFont(ofSize: 13)], for: .selected)

                vc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.black,NSAttributedString.Key.font:UIFont.systemFont(ofSize: 13)], for: .normal)

iOS13

if #available(iOS 13.0, *){

            let standardAppearance = self.tabBar.standardAppearance.copy()

            let inlineLayoutAppearance:UITabBarItemAppearance =  UITabBarItemAppearance.init()

            inlineLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor :normalColor ,NSAttributedString.Key.font:notmalFont]

            inlineLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor :selectedColor ,NSAttributedString.Key.font:selectedFont]

            standardAppearance.stackedLayoutAppearance = inlineLayoutAppearance

            self.tabBar.standardAppearance = standardAppearance

        }

注:在iOS13 使用12方法,自改文字大小,造成文字不居中。但是使用iOS13方法修改后,文字显示不全,所以在iOS13 中要两种方法都加上。




你可能感兴趣的:(iOS 13设置 tabbar字体)