美文网首页
swift 5 UITabBar的文字颜色设置

swift 5 UITabBar的文字颜色设置

作者: Johnson_9d92 | 来源:发表于2022-01-08 09:58 被阅读0次

    swift 5 UITabBar的文字颜色设置

    第一种当时,拿到UITabBarItem的appearance 前景色
    UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font:UIFont.systemFont(ofSize: 26)], for: .normal)

        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font:UIFont.systemFont(ofSize: 26)], for: .selected)
        
        self.tabBar.backgroundColor = UIColor.systemGray5
        tabBar.barTintColor = UIColor.black
    

    直接设置。
    第二种方式在
    添加每一个ChildVc,拿到

    tabBarItem?.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.gray,
                                                    NSAttributedString.Key.font : UIFont.systemFont(ofSize: 18)],
                                                   for: .normal)
                tabBarItem?.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.black,
                                                    NSAttributedString.Key.font : UIFont.systemFont(ofSize: 18)],
                                                   for: .selected)
    
                tabBarItem?.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -15)
           
                tabBarItem?.imageInsets = UIEdgeInsets(top: 5.5, left: 0, bottom: -5.5, right: 0)
    

    相关文章

      网友评论

          本文标题:swift 5 UITabBar的文字颜色设置

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