美文网首页IOS开发
iOS 13设置 tabbar字体

iOS 13设置 tabbar字体

作者: isnow | 来源:发表于2020-10-17 13:02 被阅读0次


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字体

    本文链接:https://www.haomeiwen.com/subject/kfnxmktx.html